Compare commits
No commits in common. '267eb0cd9f147c7500f14f9f2ba324b18ebc23da' and 'c2e2970fdefe6dafc35efb57ee8d63b0cff28aab' have entirely different histories.
267eb0cd9f
...
c2e2970fde
@ -1,35 +1,5 @@
|
||||
import numpy as np
|
||||
|
||||
class Board:
|
||||
def __init__(self, nbrow, nbcol):
|
||||
self.nbrow = nbrow
|
||||
self.nbcol = nbcol
|
||||
self.board = np.zeros((nbrow, nbcol))
|
||||
|
||||
def check_boundaries(self, row, col):
|
||||
try:
|
||||
self.board[row, col]
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def remove_piece(self, row, col):
|
||||
self.board[row, col] = 0
|
||||
|
||||
def insert_piece(self, row, col, player_id):
|
||||
self.board[row, col] = player_id
|
||||
|
||||
def insert_piece_into_column(self, col, player_id):
|
||||
if player_id <= 0:
|
||||
return False
|
||||
if not self.check_boundaries(0, col):
|
||||
return False
|
||||
|
||||
indices = np.where(self.board[:, col] == 0)[0]
|
||||
if indices.size > 0:
|
||||
row = indices[0]
|
||||
self.insert_piece(row, col, player_id)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -1,23 +0,0 @@
|
||||
class Rules:
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.nb_row = None
|
||||
self.nb_col = None
|
||||
|
||||
def check_board_size(self, board: Board) -> Bool:
|
||||
""" Checks if the board size is correct.
|
||||
Entries:
|
||||
self: the Rules class itself
|
||||
board -> Board: a board
|
||||
Output:
|
||||
correct -> Bool: if True, the board size is correct
|
||||
"""
|
||||
correct = True
|
||||
|
||||
if not self.nb_col == board.nb_col:
|
||||
correct = False
|
||||
|
||||
if not self.nb_row == board.nb_row:
|
||||
correct = False
|
||||
|
||||
return correct
|
Loading…
Reference in new issue