Do a "puissance 4" like game playable by 2 gamers on a computer
Understand rules of the game.
game system :
- put a chip in a column
- we have 42 chips
- we have two colors of chips (yellow and red, same number of chips for each color)
Winning:
- have a column with 4 following chips horizontally
- have a column with 4 following chips vertically
- have a column with 4 following chips in diagonals
See GameBoard
Take a matrix (or 2d list in our case)
[
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0],
[-1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0]
]
corresponds to puissance4_board_example
caption:
- 0 empty box
- 1 yellow chip
- -1 red chip
- modulo 2 is good to determine the player
- 1+1+1+1 = 4 yellow win
- -1-1-1-1 = -4 red win
This addition work in all possibles directions (vertical, horizontal, diagonals)
See GameView
See Game