Table of Contents

Cvičení 9 - Semestrální práce

Úvod

Historie a balíček

Pravidla (našeho) Scrabble

Příklad 1

.......
..ABC..
.......

...A...
..ABC..
.......

.......
..ABC..
....A..

.......
..ABCA.
.......

Příklad 2

.......
..ABC..
.......

.......
.XABCY.
.......

.......
XYABC..
.......

..X....
..Y....
..ABC..
.......

.......
..ABC..
..X.Y..

Příklad 3

.......
..ABC..
.......

.......
..ABC..
..XYZ..

.......
..ABC..
.......
..XYZ..

Výpočet skóre

.......
..A.X..
...W...
..XYZ..

.......
..ARX..
...W...
..XYZ..

.X.X.XX.
.AAAAAA.
..B.B...

.XQXQXX.
.AAAAAA.
..B.B...

Implementace

V souboru base.py jsou dále pomocné funkce:

Jak postupovat

soubor player.py

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 ")