def playGame(self): playersOut = [] drawPile = tilelist board = Board() #Dummy players for now- will have a function for this later player1 = sPlayer("blue", 28) player2 = sPlayer("red", 14) playersIn = [player1, player2] board.placePlayer(playersIn[0], 0, 0, 0) board.placePlayer(playersIn[1], 0, 2, 0) #Start everyone off with three tiles drawPile = dealTiles(playersIn, drawPile) while True: #while tile choice is invalid, keep getting different choice player = playersIn[0] newTile = player.getTileChoice() if (is_play_legal(newTile, player, board)): player.removeTile(tile) turn = play_a_turn(drawPile, playersIn, playersOut, board, newTile) playersIn = turn[1] #If turn returns true, it's over if (turn[4]): break else: drawPile = turn[0] playersOut = turn[2] gameBoard = turn[3] return "Player(s) "+playersIn+" have won!"
def dragonTileOwner(): serv = Server() board = Board() player1 = sPlayer("blue", 20) player2 = sPlayer("red", 30) playersIn = [player1, player2] playersOut = [] tile = False drawPile = copy.deepcopy(tilelist) board.placePlayer(playersIn[0], 0, 0, 0) board.placePlayer(playersIn[1], 0, 2, 0) drawPile = serv.dealTiles(playersIn, drawPile) #Ensure both players have only two tiles, which would qualify both for dragon tile while not tile: newT = player1.getTileChoice() if (serv.is_play_legal(newT, player1, board)): tile = newT player1.removeTile(tile) player2.hand = player2.hand[1:] #Let player 2 have received it on the previous turn serv.hasDragonTile = player2 #Make draw pile empty drawPile = [] serv.play_a_turn(drawPile, playersIn, playersOut, board, tile) if not (serv.hasDragonTile == player2): print "dragonTileOwner failed: hasDragonTile value is ", serv.hasDragonTile, " instead of player2" else: print "dragonTileOwner passed"
def multiElimMove(): player1 = sPlayer("blue", 20) player2 = sPlayer("red", 30) testBoard = Board() tile = Tile([[0, 1], [2, 3], [4, 5], [6, 7]]) testBoard.placePlayer(player1, 0, 0, 0) testBoard.placePlayer(player2, 0, 0, 7) testBoard.addTileToBoard(tile, 0, 0) testBoard.movePlayer(player1) testBoard.movePlayer(player2) if (player1.dead and player2.dead): print "multiElimMove passed" elif (not player1.dead): print "multiElimMove test failed, player1 not dead as expected" elif (not player2.dead): print "multiElimMove test failed, player2 not dead as expected"
def moveFromEdge(): player1 = sPlayer("blue", 20) testBoard = Board() tile = Tile([[0, 2], [1, 4], [3, 7], [5, 6]]) testBoard.placePlayer(player1, 0, 0, 0) testBoard.addTileToBoard(tile, 0, 0) testBoard.movePlayer(player1) if (player1.location == [0, 1, 7]): print "moveFromEdge test passed" else: print "moveFromEdge test failed with player location at ", player1.location, " rather than [0,1,7]." return
def multiPlayerMove(): player1 = sPlayer("blue", 20) player2 = sPlayer("red", 30) playerList = [player1, player2] testBoard = Board() tile = Tile([[0, 4], [1, 5], [2, 6], [3, 7]]) testBoard.placePlayer(player1, 5, 5, 4) testBoard.placePlayer(player2, 5, 5, 3) testBoard.addTileToBoard(tile, 5, 5) for p in playerList: testBoard.movePlayer(p) if ((player1.location == [4, 5, 5]) and (player2.location == [5, 4, 2])): print "multiPlayerMove passed" elif (player1.location != [4, 5, 5]): print "multiPlayerMove test failed, player1 location expected [4,5,5], got " + player1.location elif (player2.location != [5, 4, 2]): print "multiPlayerMove test failed, player2 location expected [5,4,2], got " + player2.location
def dragonOwnerSelfElim(): serv = Server() board = Board() player1 = sPlayer("blue", 20) player2 = sPlayer("red", 30) player3 = sPlayer("green", 30) playersIn = [player1, player2, player3] playersOut = [] tile = Tile([[0, 1], [2, 3], [4, 5], [6, 7]]) drawPile = copy.deepcopy(tilelist) board.placePlayer(playersIn[0], 0, 0, 0) board.placePlayer(playersIn[1], 0, 0, 1) board.placePlayer(playersIn[2], 0, 2, 0) drawPile = serv.dealTiles(playersIn, drawPile) #Player 1 has dragon tile. Everyone else has full hand player1.hand = player1.hand[1:] drawPile = [] serv.hasDragonTile = player1 serv.play_a_turn(drawPile, playersIn, playersOut, board, tile) if serv.hasDragonTile: print "dragonOwnerSelfElim failed: hasDragonTile value is ", serv.hasDragonTile, " instead of False" else: print "dragonOwnerSelfElim passed"
def noDragonTile(): #Create server instance and set up turn serv = Server() board = Board() player1 = sPlayer("blue", 20) player2 = sPlayer("red", 30) playersIn = [player1, player2] playersOut = [] tile = False drawPile = copy.deepcopy(tilelist) board.placePlayer(playersIn[0], 0, 0, 0) board.placePlayer(playersIn[1], 0, 2, 0) drawPile = serv.dealTiles(playersIn, drawPile) while not tile: newT = player1.getTileChoice() if (serv.is_play_legal(newT, player1, board)): tile = newT player1.removeTile(tile) serv.play_a_turn(drawPile, playersIn, playersOut, board, tile) if serv.hasDragonTile: print "noDragonTile test failed: player ", serv.hasDragonTile, " has a dragon tile." else: print "noDragonTile passed"
def dragonTileElim2(): serv = Server() board = Board() player1 = sPlayer("blue", 20) player2 = sPlayer("red", 30) player3 = sPlayer("green", 30) playersIn = [player1, player2, player3] playersOut = [] tile = Tile([[0, 4], [1, 7], [2, 3], [5, 6]]) drawPile = copy.deepcopy(tilelist) board.placePlayer(playersIn[0], 0, 0, 0) board.placePlayer(playersIn[1], 0, 0, 1) board.placePlayer(playersIn[2], 0, 2, 0) drawPile = serv.dealTiles(playersIn, drawPile) #Give everyone 1 tiles instead of 3 for p in playersIn: p.hand = p.hand[2:] drawPile = [] serv.hasDragonTile = player1 serv.play_a_turn(drawPile, playersIn, playersOut, board, tile) if not (serv.hasDragonTile == player3): print "dragonTileElim2 failed: hasDragonTile value is ", serv.hasDragonTile, " instead of player3" else: print "dragonTileElim2 passed"
def blockIllegal(): legal = Tile([[0, 2], [1, 3], [4, 6], [5, 7]]) illegal = Tile([[0, 1], [2, 3], [4, 5], [6, 7]]) testBoard = Board() player = sPlayer("blue", 30) testBoard.placePlayer(player, 0, 0, 0) player.addTileToHand(legal) player.addTileToHand(illegal) legalmoves = testBoard.findLegalMoves(player) if (illegal.paths in legalmoves): print "blockIllegal test failed, illegal move is marked as legal" elif (legal.paths not in legalmoves): print "blockIllegal test failed, legal move did not appear in list", legalmoves else: print "blockIllegal passed"
def multiTileMove(): player1 = sPlayer("blue", 20) testBoard = Board() #player would move from 0 to 2 tile1 = Tile([[0, 2], [1, 7], [3, 4], [5, 6]]) #player would continue to 7 and move to 4 tile2 = Tile([[0, 3], [1, 6], [2, 5], [4, 7]]) #player would continue to 1 and move to 5 tile3 = Tile([[0, 6], [1, 5], [2, 4], [3, 7]]) #player would continue to tick 5 (tick 0 on next tile) then stop testBoard.placePlayer(player1, 0, 0, 0) testBoard.addTileToBoard(tile1, 0, 0) testBoard.addTileToBoard(tile2, 0, 1) testBoard.addTileToBoard(tile3, 1, 1) testBoard.movePlayer(player1) if (player1.location == [2, 1, 0]): print "multiTileMove test passed" else: print "multiTileMove test failed with player location at ", player1.location, " rather than [2,1,0]."
from sPlayer import sPlayer from Tile import Tile from Board import Board from Server import Server from tilelist import tilelist import copy #game class instances to be used in testing below splayer1 = sPlayer("blue", 20) splayer2 = sPlayer("red", 30) testtile = Tile([[0, 1], [2, 3], [4, 5], [6, 7]]) test = Board() #TILE TESTS def TileTests(): #test that constructor works if (testtile.paths != [[0, 1], [2, 3], [4, 5], [6, 7]]): print "Tile constructor test failed!" #test that rotating once works testtile.rotate() #Rotating once should change paths to [[2,3],[4,5],[6,7],[0,1]], test if (testtile.paths != [[2, 3], [4, 5], [6, 7], [0, 1]]): print "Expected [[2,3],[4,5],[6,7],[0,1]] but received " + str( testtile.paths) print "Tile rotation test failed!" #test that multi-rotation works (3 more rotations should result in original tile) testtile.rotate() testtile.rotate()