def test_Ladder(self): #Arrage myBoard = ChutesAndLaddersBoard(10, '-', 2) expPlayerLoc = {0: 38, 1: 0} #Act myBoard.makeMove(0, 1) actPlayerLoc = myBoard.PlayerLoc #Assert self.assertEqual(expPlayerLoc, actPlayerLoc, "Player landing on ladder is wrong")
def test_MoveLeftToRight(self): #Arrage myBoard = ChutesAndLaddersBoard(10, '-', 2) expPlayerLoc = {0: 5, 1: 0} #Act myBoard.makeMove(0, 5) actPlayerLoc = myBoard.PlayerLoc #Assert self.assertEqual(expPlayerLoc, actPlayerLoc, "Player initial move is wrong")
def test_MoveLeftToRightUp(self): #Arrage myBoard = ChutesAndLaddersBoard(10, '-', 2) expPlayerLoc = {0: 12, 1: 0} #Act myBoard.makeMove(0, 6) myBoard.makeMove(0, 6) actPlayerLoc = myBoard.PlayerLoc #Assert self.assertEqual(expPlayerLoc, actPlayerLoc, "Player moving left to right then up is wrong")
def __init__(self): """ Create ChutesAndLadders game class. """ print("\nWelcome to Chutes and Ladders!") self.maxSpin = 6 super().__init__(ChutesAndLadders.turn, ChutesAndLadders.boardSize, ChutesAndLadders.delimeter) self.getPlayers() self.board = ChutesAndLaddersBoard(self.boardSize, self.delimeter, len(self.players)) self._playGame()
def test_BoardCandL(self): #Arrage expCandLCount = 19 #Act myBoard = ChutesAndLaddersBoard(10, '-', 2) actCandLCount = len(myBoard.CandLmap) #Assert self.assertEqual(expCandLCount, actCandLCount, "CandLmap count is wrong")
def test_Players(self): #Arrage playerNum = 2 expPlayerLoc = {0: 0, 1: 0} #Act myBoard = ChutesAndLaddersBoard(10, '-', playerNum) actPlayerLoc = myBoard.PlayerLoc #Assert self.assertEqual(expPlayerLoc, actPlayerLoc, "Player start point is wrong")
def test_BoardSize(self): #Arrange expBoardSize = 10 #Act myBoard = ChutesAndLaddersBoard(expBoardSize, '-', 2) rowSize = len(myBoard.GameBoard) colSize = len(myBoard.GameBoard[1]) #Assert self.assertEqual(expBoardSize, rowSize, "Row Size not " + str(expBoardSize)) self.assertEqual(rowSize, colSize, "Row Size and Col Size not equal")
def test_WinnerBeyond(self): #Arrage myBoard = ChutesAndLaddersBoard(10, '-', 2) expWinner = 1 #Act myBoard.makeMove(0, 6) myBoard.makeMove(0, 6) myBoard.makeMove(0, 6) myBoard.makeMove(0, 6) myBoard.makeMove(0, 4) myBoard.makeMove(0, 6) myBoard.makeMove(0, 6) myBoard.makeMove(0, 6) actWinner = myBoard.checkWinner(0) #Assert self.assertEqual(expWinner, actWinner, "Player landing beyond winning spot [0,0] is wrong")
class ChutesAndLadders(Game): turn = 0 delimeter = "_" boardSize = 10 # CONSTRUCTOR @MyLogger.log(["File"]) def __init__(self): """ Create ChutesAndLadders game class. """ print("\nWelcome to Chutes and Ladders!") self.maxSpin = 6 super().__init__(ChutesAndLadders.turn, ChutesAndLadders.boardSize, ChutesAndLadders.delimeter) self.getPlayers() self.board = ChutesAndLaddersBoard(self.boardSize, self.delimeter, len(self.players)) self._playGame() # PROTECTED METHODS def _initGame(self): pass #have players spin and move @MyLogger.log(["File"]) def _playGame(self): playerCnt = len(self.players) gameWon = False while (not (gameWon)): input( f"{self.players[self.turn]} ({str(self.turn)}) press Enter to spin" ) print("\n") spin = random.randint(1, self.maxSpin) print(f"You spun a {str(spin)}") self.board.makeMove(self.turn, spin) print("\n") self.board.printBoard() gameWon = self.board.checkWinner(self.turn) if gameWon: print("\n") print(f"{self.players[self.turn]} wins!\n") else: self.turn = 0 if self.turn + 1 > playerCnt - 1 else self.turn + 1 # Method to get a human player's move def _getMoveHuman(self): pass # Method to determine cpu move def _getMoveCPU(self): pass