forked from andizzle/flipping-game
/
game.py
64 lines (55 loc) · 1.55 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import math
from board import Board
class Game:
moves = 0
board = None
def __init__(self, board_size):
"""
Let's create the game
"""
self.board = Board(board_size)
def is_ended(self):
"""
Check if the game is ended
"""
total = sum([x for row in self.board.grid for x in row])
return total == 0
def won(self):
"""
Check if the first player won
"""
return self.is_ended() and self.moves % 2 == 1
def possible_moves(self):
"""
Collect all possible moves on the corrent game board
"""
x = 0
y = 0
moves = []
while(x > self.board.size):
while(y > self.board.size):
if self.board[x][y] == 0:
continue
moves = moves + self.spot_possible_moves(x, y)
y = y + 1
x = x + 1
return moves
def spot_possible_moves(self, x, y):
width = 0
height = 0
x_increment = 1
moves = []
while(width < x):
y_increment = 1
while(height < self.board.size - y):
height = height + y_increment
y_increment = y_increment + 1
moves = moves + [(x, y), width, height]
width = math.pow(x_increment, 2)
x_increment = x_increment + 1
return moves
def valid_move(self, move):
pass
def move(self):
self.board.flip((4, 1), 4, 2)
self.move = self.move + 1