Add .gitignore
This commit is contained in:
parent
18553340f2
commit
32b944a6db
|
@ -0,0 +1 @@
|
||||||
|
*.pyc
|
|
@ -16,6 +16,9 @@ class Board:
|
||||||
# four squares, diagonlally from eachother for symmetry.
|
# four squares, diagonlally from eachother for symmetry.
|
||||||
# Note that because the board is symettrical, one of the players must
|
# Note that because the board is symettrical, one of the players must
|
||||||
# have an advantage... but is it player 1 or player 2?
|
# have an advantage... but is it player 1 or player 2?
|
||||||
|
# CP: How does it follow that symmetrical board -> imbalance?
|
||||||
|
# CP: What if a game worked by flipping a coin at the beginning of each turn
|
||||||
|
# CP: to decide which player will play?
|
||||||
return [[0,0,0,0],[0,2,3,0],[0,3,2,0],[0,0,0,0]]
|
return [[0,0,0,0],[0,2,3,0],[0,3,2,0],[0,0,0,0]]
|
||||||
|
|
||||||
def get_active_player_code(self):
|
def get_active_player_code(self):
|
||||||
|
@ -89,6 +92,7 @@ class Board:
|
||||||
# Note that a "move" consists of both moving an amazon and shooting.
|
# Note that a "move" consists of both moving an amazon and shooting.
|
||||||
# This means that a move has three values: chosen amazon's starting position,
|
# This means that a move has three values: chosen amazon's starting position,
|
||||||
# the amazon's new position, and the position of the burned square.
|
# the amazon's new position, and the position of the burned square.
|
||||||
|
# CP: Great--this is a sensible way of representing a move.
|
||||||
move_options=[]
|
move_options=[]
|
||||||
amazons = self.get_active_amazons_positions() # Find the amazons.
|
amazons = self.get_active_amazons_positions() # Find the amazons.
|
||||||
for amazon in amazons:
|
for amazon in amazons:
|
||||||
|
@ -133,6 +137,7 @@ class Board:
|
||||||
|
|
||||||
def get_possible_successor_states(self):
|
def get_possible_successor_states(self):
|
||||||
# This just uses the other function and applies is to every possible move.
|
# This just uses the other function and applies is to every possible move.
|
||||||
|
# CP: Lovely!
|
||||||
return [self.get_successor_state(move) for move in self.possible_moves()]
|
return [self.get_successor_state(move) for move in self.possible_moves()]
|
||||||
|
|
||||||
def is_empty(self, square):
|
def is_empty(self, square):
|
||||||
|
@ -142,6 +147,8 @@ class Board:
|
||||||
# Don't forget that while we say (x,y), the indices are refernced as [y][x]
|
# Don't forget that while we say (x,y), the indices are refernced as [y][x]
|
||||||
# since the rows are above and below eachother (y) and columns adjacent (x):
|
# since the rows are above and below eachother (y) and columns adjacent (x):
|
||||||
if (x in range(len(self.state[0]))) and (y in range(len(self.state[0]))):
|
if (x in range(len(self.state[0]))) and (y in range(len(self.state[0]))):
|
||||||
|
# This could be simplified to:
|
||||||
|
# return self.state[x][y] == 0
|
||||||
if self.state[x][y] == 0:
|
if self.state[x][y] == 0:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,6 +3,11 @@ from view import *
|
||||||
|
|
||||||
board = Board()
|
board = Board()
|
||||||
|
|
||||||
|
# CP: Different notation systems should be aligned with different layers in the
|
||||||
|
# application. The Board knows nothing of 'a' or '4'. This intuition suggests that
|
||||||
|
# `translator` and `good_square_checker` should be methods of a View. The entire
|
||||||
|
# View is swappable if we later switch to another View (e.g. my Retro app)
|
||||||
|
# CP: Should scale to n*n boards
|
||||||
translator = {
|
translator = {
|
||||||
'a4':[0,0], 'a3':[1,0], 'a2':[2,0], 'a1':[3,0],
|
'a4':[0,0], 'a3':[1,0], 'a2':[2,0], 'a1':[3,0],
|
||||||
'b4':[0,1], 'b3':[1,1], 'b2':[2,1], 'b1':[3,1],
|
'b4':[0,1], 'b3':[1,1], 'b2':[2,1], 'b1':[3,1],
|
||||||
|
@ -10,18 +15,23 @@ translator = {
|
||||||
'd4':[0,3], 'd3':[1,3], 'd2':[2,3], 'd1':[3,3]
|
'd4':[0,3], 'd3':[1,3], 'd2':[2,3], 'd1':[3,3]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# CP: Should scale to n*n boards
|
||||||
def good_square_checker(square):
|
def good_square_checker(square):
|
||||||
square_names = ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4', 'c1', 'c2', 'c3', 'c4', 'd1', 'd2', 'd3', 'd4']
|
square_names = ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4', 'c1', 'c2', 'c3', 'c4', 'd1', 'd2', 'd3', 'd4']
|
||||||
|
# CP: This could be simplified to:
|
||||||
|
# return square in square_names
|
||||||
if square not in square_names:
|
if square not in square_names:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# CP: Let `View` handle this.
|
||||||
def turn():
|
def turn():
|
||||||
move_chosen = False
|
move_chosen = False
|
||||||
while move_chosen == False:
|
while move_chosen == False:
|
||||||
tui(board)
|
tui(board)
|
||||||
print("Valid coordinates look like: \'b2\' or \'c4\'")
|
print("Valid coordinates look like: \'b2\' or \'c4\'")
|
||||||
|
# CP: Use None to represent nullity
|
||||||
amazon = 'none'
|
amazon = 'none'
|
||||||
move = 'none'
|
move = 'none'
|
||||||
burn = 'none'
|
burn = 'none'
|
||||||
|
@ -38,6 +48,7 @@ def turn():
|
||||||
board.state = board.get_successor_state(choice)
|
board.state = board.get_successor_state(choice)
|
||||||
move_chosen = True
|
move_chosen = True
|
||||||
else:
|
else:
|
||||||
|
# CP: Let `View` handle this.
|
||||||
input("That is not a valid move. Press enter to continue.")
|
input("That is not a valid move. Press enter to continue.")
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,4 +58,19 @@ def play():
|
||||||
tui(board)
|
tui(board)
|
||||||
print("Player "+str(board.get_active_player_code()-1)+" loses!")
|
print("Player "+str(board.get_active_player_code()-1)+" loses!")
|
||||||
|
|
||||||
|
# CP: Once refactored, `game.py` should be something like this:
|
||||||
|
"""
|
||||||
|
from game import Game
|
||||||
|
from view import View
|
||||||
|
|
||||||
|
game = Game()
|
||||||
|
view = View()
|
||||||
|
while not game.is_over():
|
||||||
|
move = view.get_next_move(game)
|
||||||
|
game.play_move(move)
|
||||||
|
view.conclude_game(game)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
play()
|
play()
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
from board import *
|
from board import *
|
||||||
from os import system, name
|
from os import system, name
|
||||||
|
|
||||||
|
# It's probably cleanest for the view to be a class and for it
|
||||||
|
# to handle all input-output to the user, including
|
||||||
|
# - rendering board state
|
||||||
|
# - representing
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
if name == 'nt':
|
if name == 'nt':
|
||||||
_ = system('cls')
|
_ = system('cls')
|
||||||
else:
|
else:
|
||||||
_ = system('clear')
|
_ = system('clear')
|
||||||
|
|
||||||
|
# CP: Should scale to n*n boards
|
||||||
def tui(board): #This displays the board state to the user
|
def tui(board): #This displays the board state to the user
|
||||||
clear()
|
clear()
|
||||||
print(" a b c d")
|
print(" a b c d")
|
||||||
|
|
Loading…
Reference in New Issue