Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been given the assignment to create a quite complicated to me, but simple to some C game. The program will run and generate 25 random numbers between 1 to 100 (no repeats). The game is between two users.
Both the players will get two guesses each time. Every correct guess will be counted as 1 correct answer and will be displayed on the screen in the board.
The player having more number of correct guesses will be a winner.
The game will continue until the board is completely revealed.
The first screen should ask the user for his name, print a welcome message, and displays an empty 5x5 board. But this 5x5 board has the values in it internally
Now the program should ask the number of players (1 or 2)
If one, ask one name and second is computer and if 2 ask two names
For playing against computer, you are asked for two guesses and every correct guess is shown on the board.
Now 2 guesses for computer would be taken and shown on the screen.
I have tried everything to my knowledge to complete this but I lack a full understanding of C. Any help would be appreciated. I did not include my code because, honestly its just a mess and does not even run.
I would like to see someone be able to make such a game, so that I can study the logic. NOT COPY THE WORK
Simple steps. Start small and grow.
Easy one is to remove all questions to the user(s). Hard code the answers in the program. You can retrofit the IO later.
Start with a way ot generating 25 random numbers and load them into an array. Place the array in a global variable. You need a another array to show when a number is sucessfully guessed.
Now write a function to display that guessed array as 5X5.
Gradually build the program up
Always make functions
generate_array
show_guessed
....
If get stuck on specific things then post a new question.
This is not a direct answer, but a very long comment with some requests for more information and effort.
The problem I have with your request is that I see zero effort. I see a request for teh C0d3z and a promise not to cheat after receiving something that makes it far too easy to cheat.
What I, and probably others here, want to see is effort and some attempt.
Do you know how to print text to the screen like you see in the requirements? Do you know how to print text at all? If so, make the print routines and state this.
Do you know how to generate random numbers? If so, say so in your question and we see effort.
Do you know how to receive input from the user?
Do you know what an array is?
Do you know how to save code in your editor and compile it?
You can see that without any sort of background or starting code, we don't know where you are in your learning.
So...
Post an attempt at solving your problem in your question. If you are truly so new to coding that you cannot do this, then you need to sit down with your professor / TA / whomever and tell them this. Reading through your teaching material (textbook or whatever) should help a whole lot as well. This assignment feels like something I would see towards the end of a beginner's C class. If this is where you are, and you really have no clue what to do, then you may need to retake the class.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
Let me start by saying that I'm a beginner programmer that knows very basic C
The exact code I'm working on doesn't matter here its just that I've run into a very odd problem (I'm messing around with ASCII graphics)
I want to differentiate between two 'O' characters. I could just use different characters but I want it to look good. I tried using Unicode to differentiate them (since Latin O and Greek Omicron look the same) but it won't work if I send it to someone else (since my output is on command prompt) edit: won't work if I send it to someone since command prompt must be manually configured to allow unicode characters (atleast to my understanding)
I don't know if using structures would work and I want to write this in C and not any other OOP language like python (because I'm practicing C)
So is there any logic I could use to do this?
EDIT: I want to apply different behaviours to both O and there will be multiple O of each type on screen (ik this is what objects do but pls help me with a logic for C)
EDIT 2: Apparently my question is very vague so I'll elaborate
I'm having a 2d array that I'm using as a game screen
I want O to come in from each side (top bottom right left), scroll across the screen and exit from the other side
I already came up with the logic to make it work for a single side but the problem comes in when I want to make it work for all sides
My current logic can't differentiate between an O that has to go left and and O that has to go down
Hence why I want to different between two instances of O
(I haven't posted my code since I just need the logic and want to solve the actual code by myself and also it's probably very inefficient or convuluted etc)
tldr: I want to differentiate between "O" and "O"
My current logic can't differentiate between an O that has to go left and and O that has to go down
Your problem is that you don't differentiate internal representation and external presentation.
You have two distinct objects that move across the screen. They both look like an O character. This doesn't mean your program should store them both as 'O', some variation of 'O' such as the omicron character. The program can store e.g. numbers 1 and 2, or any two different objects that are convenient to work with, and display an O in place of either.
This is not a language-specific question, but for the sake of conversation, I currently work in C# 7.
Over the years I've successfully implemented the Alpha Beta pruning algorithm (even in PASCAL, 35 years ago :)
Each time, I've created semi-deep-copies (discussed below) of the game state which is recursed for each node. I've often wondered if this is necessary and if perhaps I'm not truly understanding the algorithm.
The interweb is full of requests for help for TicTacToe, which makes me think that this must be a common school assignment question - which kinda clogs searches on this fairly basic topic.
Semi-deep-copies ... it appears to me that each node should know:
the full state of the board
the player whose turn it is
the state of play - ie: { playing, Player1 win, Player2 win, draw }
My question is: does each node need its own copy of the board? ... for example Chess has 8x8 grid ... is there something more subtle to the algorithm, or do these nodes each need their own snap-shot of the board state? Is there some cool way (other than copy and apply-possible-move) that nodes can use to derive their state from their parent?
Perhaps someone can explain or point to a "read this, dummy" post, or just confirm that I need to make these instances, as I've attempted to describe, with each recursive call having its own in-memory copy of the game board.
I realize that over the last few decades, memory has become cheap... but combinatorial-explosion is still the main topic. Cheers.
I am not sure if this answers your question. But could you instead of making a copy each turn do the move, make the recursive call, and then undo the move instead? Something like:
board.make_move(move)
eval = minimax(board, ....)
board.unmake_move(move)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hi friends I was working on a project where we need to use quite a few multidimensional arrays. I am using for loops to access different array elements, then I just thought what if I don’t have a liberty to use looping? How am I going to access array element?
I am new to C, so thought of discussing here, I am sure there might be thousans of people who could have thought the same way, and hopefully found the solution.
Below example of multidimensional array is give, please guide me.
Thanks
static int t[3][2][4] = { {2,4,3,6,
1,6,7,9,},
{8,2,1,1,
2,3,7,3,},
{1,6,2,4,
0,7,9,5,},
};
Please Help me...thanks!
If you need to go through all of the values inside the loop without manual handling (i.e. x = t[1][1][1] then x = t[1][1][2] etc) then you want to use loops, enhanced loops or iterators. However since you're using C the only of those three options available are standard loops, which you're trying not to use. So... there's mo straight forward way to do that really.
If you're willing to use some other C libraries however then there may be more options for you. Iterator libraries probably exist.
A non-straightforward way to do it (if you're looking for one) could be through recursion, however that's really quite wasteful. I advise you just use loops :P
What are you trying to prove with loops and without loops should be first thought.
If u want to access all the elements and not use loop is like writing a lot of code manually and waste of memory(in your case 3 * 2 * 4 no of lines instead of few ).
Instead of showing the array if you had put in your code how and where you accessing elements it would have been more clear to tell what you wanted .
So, I am a basic programmer in flash and this weekend I have to make a small mini game. This is where I get confused...I have 1 movieclip which has 5 labels ( each showing a different shape). I also have a dynamic text field which I have text or (a string) that will need to match the movieclip. Meaning, if the text displays circle, and the shape is circle, if you click the screen you win. if they dont match, you lose. So I am asking this in order to find out, how to create 2 arrays, randomize them then compare the value. I know how to set everything on timers and give scores, I just cant get figure this part out. AS3 and I are having a bad day. Any ideas, even pseudo code helps...or just a flow , something please ! lol thanks in advance
Regarding randomizing an array, have a look at this elaborate article at Activetuts, which specifically aims at Actionscript. It provides documented code with clear illustrations and tips. You could also check out the Fisher-Yates shuffle for some pseudo-code.
I don't quite get your question with regards to comparing the strings.. In AS3, you can use == to see if the strings are equal.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have to do a Sokoban solver (http://en.wikipedia.org/wiki/Sokoban).
Have you ever done one? I am searching for tips, not for code. Like "you may use the IDA* alg" or "I used that heuristic and it was quite good" or "I use that tech no avoid deadlocks".
Basically I want to write on a paper the strategy before writing any code.
I have written my Master's thesis on Sokoban algorithms. I aimed to provide a good overview on the techniques used in Sokoban solvers. It does not provide definite answers, but might provide a good starting point for someone interested in writing a Sokoban solver.
http://weetu.net/Timo-Virkkala-Solving-Sokoban-Masters-Thesis.pdf
Terms
field - the level, whole playing area of the current game.
position - a phase, set-up in the field.
final position - a position in which no turn is possible - either the goal or a deadlock.
box - same as crate.
Theory
Just a little bit of logic - it seems obvious but we'll use it in the implementation part.
So - about every game of Sokoban, we can say that it is one of these:
solvable, unsolved - in the process of solving
solvable, solved - the goal
unsolvable, unsolved - if our implementation yields no results, and there are no more possible moves / combinations of moves
Now - a Sokoban game consists of turns that are:
moves - the character can move in an area defined by walls and/or boxes, this area is smaller or equal (if not counting the walls, and there are no boxes) to the whole playing area - however, moving the character around the field makes no difference except score, which is irrelevant for the actual solution - let's ignore it for now
pushes - pushing the boxes is much more important, and can potentially lead to our goal - solving the field - by pushing the boxes at their respective goals
A box can be:
in-goal - most likely this box does not need to be moved, and some rules can prohibit a box from moving when at a goal position (very unusual)
pushable - in 1 to 4 directions
unpushable, not at goal
blocked by 2 walls - the current position is unsolvable no matter what
other - we will get to this box later - for now a crate stands in our way
Process
This is the step-by-step process we will use in solving (definitions underneath):
populate possibleTurnsn with every directly accessible push (pushable or in-goal) in the current position, with player at the current place
take the first item in possibleTurnsn, remove it and execute it
see if the current position:
is final - goal - solved, do not do anything
is final - deadlock - this turn led to a deadlock, don't populate it anymore, go back to 2. step, n stays the same
is not final - increment n and populate possibleTurnsn with possible turns in this position
Definitions:
possibleTurnsx - a two dimensional array, or an array of arrays - the x defines the "depth" of the turns
n - in the beginning is zero, will be incremented in the execution of the algorithm above
Tips
Finally - the process above will leave you with a combination of turns that will leave to a solved position. Last thing to do is to use an algorithm like A* to determine the shortest route between these turns / pushes, to maximize the speed and score, minimize number of in-game turns.
You can create a brute force solver that tries to move your man in every possible direction. By using recursion (or a stack) you can track back your steps if a solution is not found.
A* probably won't do you any good, because you don't have to find your way through a maze, but also need to move the boxes. This means you may need to take a step back in the same direction you came from after moving a box. So for every step you need to evaluate all directions, including the one you came from. That is, unless you didn't move a box in the previous step.
[edit]
You could use A* to make it a little smarter; to find a way from your current position to any of the positions you can move a box from. That would probably make your solution more efficient, because you won't have to track all positions inbetween, but only the positions from the last box you pushed to the next box you'll push.