Search
player.py
base.py
self.tournament
self.board[i][j]
self.board[0][0]
self.board[14][14]
“”
BasePlayer
....... ..ABC.. .......
...A... ..ABC.. .......
....... ..ABC.. ....A..
....... ..ABCA. .......
....... .XABCY. .......
....... XYABC.. .......
..X.... ..Y.... ..ABC.. .......
....... ..ABC.. ..X.Y..
....... ..ABC.. ..XYZ..
....... ..ABC.. ....... ..XYZ..
....... ..A.X.. ...W... ..XYZ..
....... ..ARX.. ...W... ..XYZ..
.X.X.XX. .AAAAAA. ..B.B...
.XQXQXX. .AAAAAA. ..B.B...
Player
self.board
self.move()
self.rows
self.cols
self.weight
self.dictionary
word
word in self.dictionary
self.bag
self.myScore
update
self.otherScore
self.lettersInBag
self.cellValue(row, col)
self.letterValue(letter)
self.inBoard(row, col)
self.isEmpty(row, col)
self.board[row][col]
self.print()
self.update()
self
V souboru base.py jsou dále pomocné funkce:
base.readDictionary(soubor)
base.createInitialBag()
base.createBoard(word)
base
player.move()
None
return [ [0,7,'A'] ]
len(self.bag)
move()
__init__
if name == “main”:
afterMove
import base import random import copy class Player(base.BasePlayer): def __init__(self, name, dictionary, board, bag, bigBagSize): base.BasePlayer.__init__(self, name, dictionary, board, bag, bigBagSize) #always keep this line and DON't change it self.text = "myGreatPlayer" #fill the name of your awesome player! #bellow you can define your own variables. Don't forget to use 'self.' to adress them correctly def move(self): """ the main function of your player. This function is called by the gaming server to obtain your move. Possible moves are: return None - this means to 'pass' (score/board/bag are not changed) return "hello" - string of letters that you want to replace. Letters can repeat. Only letters in 'self.bag' can be used here. Not more than 7 letters. return [ [r1,c1,L1], [ r2,c2,L2] ... [rn,cn,Ln] ], where 'r_x' is row, 'c_x' is columns and 'Lx' is the letter that you want to place to the board. You don't have to place these letters to self.board, it will be done anyway by Brute """ return None; if __name__ == "__main__": words = base.readDictionary('dic.txt') #words is represented as python-dictionray board = base.createBoard("ABACUS") #this word should be from the dictionray board = base.createBoard(random.choice(list(words))) #random word from the dictionray bag = base.createInitialBag() player1bag = bag[0:7] #letters for the player1 player2bag = bag[7:14] #letters for the player2 bag = bag[14:] #remove first 14 letters p1 = Player("player1", words, board, player1bag); p2 = Player("player2", words, board, player2bag); p1.print() noChangeMoves = 0; while noChangeMoves < 6: result = p1.move() #first player plays s1 = afterMove(p1, result, p2, board) #determine the type of move, update both player, return change of score p1.print() result = p2.move(); #second player plays s2 = afterMove(p2, result, p1, board) #determine the type of move, update both player, return change of score p2.print() if s1 + s2 == 0: noChangeMoves+=1 else: noChangeMoves = 0 print("Game finished after " , noChangeMoves , " moves without change of score ")