Game Development Reference
In-Depth Information
The game is now over and the winner has been declared. We should call our
playAgain() function, which returns True if the player typed in that they want to play
another game. If playAgain() returns False (which makes the if statement's
condition True ), we break out of the while loop (the one that started on line 248), and
since there are no more lines of code after this while-block, the program terminates.
Otherwise, playAgain() has returned True (which makes the if statement's
condition False ), and so execution loops back to the while statement on line 248 and a
new game board is created.
Summary: Reviewing the Reversi Game
The AI may seem almost unbeatable, but this isn't because the computer is very smart.
The strategy it follows is very simple: move on the corner if you can, otherwise make the
move that will flip over the most tiles. We could do that, but it would take us a long time to
figure out how many tiles would be flipped for every possible valid move we could make.
But calculating this for the computer is very simple. The computer isn't smarter than us, it's
just much faster!
This game is very similar to Sonar because it makes use of a grid for a board. It is also
like the Tic Tac Toe game because there is an AI that plans out the best move for it to take.
This chapter only introduced one new concept: using the bool() function and the fact that
empty lists, blank strings, and the integer 0 all evaluate to False in the context of a
condition.
Other than that, this game used programming concepts that you already knew! You don't
have to know very much about programming in order to create interesting games. However,
this game is stretching how far you can get with ASCII art. The board took up almost the
entire screen to draw, and the game didn't have any color.
Later in this topic, we will learn how to create games with graphics and animation, not
just text. We will do this using a module called Pygame, which adds new functions and
features to Python so that we can break away from using just text and keyboard input.
Search WWH ::




Custom Search