示例#1
0
 def processInput(self, game, sq= -1):
     self.game = game
     
     if(sq == -1):
         return
     
     if(self.status == const.IDELING):
         if(self.game.board[sq] == 0 or (const.WHITE if self.game.board[sq] > 0 else const.BLACK) != self.color ):
             return
         
         #get possible moves and test them if valid
         self.possible_moves = []     
         for move in self.game.getValidMoves():
             if(bo.getBits(move, *const.MOVE_START) == sq):
                 self.possible_moves.append(move)
                 
         #highlight possible moves
         self.manager.gui.gameDisplay.removeHighlight()
         for move in self.possible_moves:
             move_type = bo.getBits(move, *const.MOVE_TYPE)
             color_highlight = 0
             if(move_type in (const.NORMAL_MOVE, const.DOUBLE_STEP) ):
                 color_highlight = 0
             elif(move_type in (const.CAPTURE, const.ENPASSANT_CAPTURE) ):
                 color_highlight = 1
             elif(move_type == const.CASTLING ):
                 color_highlight = 2
             else:
                 color_highlight = 3
             
             self.manager.gui.gameDisplay.highlightTile(bo.getBits(move, *const.MOVE_DEST), color_highlight)
         
         if(self.possible_moves != [] ):
             self.status = const.PICKING
         
     elif(self.status == const.PICKING):
         selected_move = -1
             
         #find corresponding move
         for move in self.possible_moves:
             if(bo.getBits(move, *const.MOVE_DEST) == sq):
                 selected_move = move
                 break
                 
         if(selected_move != -1):
             if(bo.getBits(selected_move, *const.MOVE_TYPE) == const.PROMOTION):
                 dialog = prom_dialog.PromotionDialog()
                 selected_move |= dialog.result << const.MOVE_PROM[0]
             
             self.result = selected_move
             
             self.manager.master.event_generate("<<turn_complete>>")
             
         self.manager.gui.gameDisplay.removeHighlight()
         self.status = const.IDELING
示例#2
0
    def updateHistoryList(self):
        self.gui.history_lb.delete(0, tk.END)

        #move = self.game.history[-1][0]

        for history_note in self.history:
            move = history_note[0]

            sq_start = bo.getBits(move, *const.MOVE_START)
            sq_dest = bo.getBits(move, *const.MOVE_DEST)
            fig_start = bo.getBits(move, *const.MOVE_FIG_START)
            fig_cap = bo.getBits(move, *const.MOVE_FIG_CAPTURE)
            fig_prom = bo.getBits(move, *const.MOVE_PROM) + 2
            move_type = bo.getBits(move, *const.MOVE_TYPE)
            color = bo.getBits(move, *const.MOVE_COLOR)

            rank_start = bb.rank(sq_start)
            rank_dest = bb.rank(sq_dest)

            line_start = bb.line(sq_start)
            line_dest = bb.line(sq_dest)

            comb_chr = '-'
            if (fig_cap != 0):
                comb_chr = 'x'

            suffix = ''
            if (move_type == const.PROMOTION):
                suffix = " =" + const.ASCII_FIG[color][fig_prom]
            history_entry = "%c%c%i%c%c%i%s" % (
                const.ASCII_FIG[color][fig_start],
                chr(97 + line_start), rank_start + 1, comb_chr,
                chr(97 + line_dest), rank_dest + 1, suffix)

            self.gui.addToHistory(history_entry)
示例#3
0
    def undoMove(self):
        last_move = self.history.pop()

        sq_start = bo.getBits(last_move[0], *const.MOVE_START)
        sq_dest = bo.getBits(last_move[0], *const.MOVE_DEST)

        fig_start = bo.getBits(last_move[0], *const.MOVE_FIG_START)
        fig_capture = bo.getBits(last_move[0], *const.MOVE_FIG_CAPTURE)

        fig_prom = bo.getBits(last_move[0], *const.MOVE_PROM) + 2

        move_type = bo.getBits(last_move[0], *const.MOVE_TYPE)

        note = last_move[1]

        #sq_start, sq_dest, fig_start, fig_capture, move_type, note = last_move
        self.playerTurn = not self.playerTurn

        self.note = note

        self.board[sq_start] = fig_start * (-1 if self.playerTurn else 1)
        self.board[sq_dest] = fig_capture * (-1 if not self.playerTurn else 1)

        self.figures[fig_start][self.playerTurn] &= ~bb.mask64[sq_dest]
        self.figures[fig_start][self.playerTurn] |= bb.mask64[sq_start]

        if (fig_start == const.KING):
            self.king_pos[self.playerTurn] = sq_start

        if (fig_capture):
            self.figures[fig_capture][not self.
                                      playerTurn] |= bb.mask64[sq_dest]
            self.material_value -= aiv.MATERIAL_VALUE[fig_capture] * (
                -1 if self.playerTurn else 1)

        if (move_type == const.ENPASSANT_CAPTURE):
            self.board[sq_dest - 8 +
                       16 * self.playerTurn] = (1 if self.playerTurn else -1)
            self.figures[
                const.PAWN][not self.playerTurn] |= bb.pawn_singlestep[
                    not self.playerTurn][sq_dest]
            self.material_value -= aiv.MATERIAL_VALUE[const.PAWN] * (
                -1 if self.playerTurn else 1)

        if (move_type == const.PROMOTION):
            self.figures[fig_prom][self.playerTurn] ^= bb.mask64[sq_dest]
            self.material_value -= (aiv.MATERIAL_VALUE[fig_prom] -
                                    aiv.MATERIAL_VALUE[const.PAWN]) * (
                                        -1 if self.playerTurn else 1)

        if (move_type == const.CASTLING):
            side = bb.line(sq_dest) == const.G
            self.board[bb.castling_rook_start_sq[self.playerTurn]
                       [side]] = const.ROOK * (-1 if self.playerTurn else 1)
            self.board[bb.castling_rook_dest_sq[self.playerTurn][side]] = 0
            self.figures[const.ROOK][self.playerTurn] ^= bb.mask64[
                bb.castling_rook_dest_sq[self.playerTurn][side]] | bb.mask64[
                    bb.castling_rook_start_sq[self.playerTurn][side]]

        self.refreshAllFigBitboard()
示例#4
0
 def undoMove(self):
     last_move = self.history.pop()
     
     sq_start = bo.getBits(last_move[0], *const.MOVE_START)
     sq_dest = bo.getBits(last_move[0], *const.MOVE_DEST)
     
     fig_start = bo.getBits(last_move[0], *const.MOVE_FIG_START)
     fig_capture = bo.getBits(last_move[0], *const.MOVE_FIG_CAPTURE)
     
     fig_prom = bo.getBits(last_move[0], *const.MOVE_PROM) + 2
     
     move_type = bo.getBits(last_move[0], *const.MOVE_TYPE)
     
     note = last_move[1]
     
     #sq_start, sq_dest, fig_start, fig_capture, move_type, note = last_move
     self.playerTurn = not self.playerTurn
     
     self.note = note
     
     self.board[sq_start] = fig_start * (-1 if self.playerTurn else 1)
     self.board[sq_dest] = fig_capture * (-1 if not self.playerTurn else 1)
     
     self.figures[fig_start][self.playerTurn] &= ~bb.mask64[sq_dest]
     self.figures[fig_start][self.playerTurn] |= bb.mask64[sq_start]
     
     if(fig_start == const.KING):
         self.king_pos[self.playerTurn] = sq_start
     
     if(fig_capture):
         self.figures[fig_capture][not self.playerTurn] |= bb.mask64[sq_dest]
         self.material_value -= aiv.MATERIAL_VALUE[fig_capture] * (-1 if self.playerTurn else 1)
         
     if(move_type == const.ENPASSANT_CAPTURE):
         self.board[sq_dest-8+16*self.playerTurn] = (1 if self.playerTurn else -1)
         self.figures[const.PAWN][not self.playerTurn] |= bb.pawn_singlestep[not self.playerTurn][sq_dest]
         self.material_value -= aiv.MATERIAL_VALUE[const.PAWN] * (-1 if self.playerTurn else 1)
         
     if(move_type == const.PROMOTION):
         self.figures[fig_prom][self.playerTurn] ^= bb.mask64[sq_dest]
         self.material_value -= (aiv.MATERIAL_VALUE[fig_prom] - aiv.MATERIAL_VALUE[const.PAWN]) * (-1 if self.playerTurn else 1)
         
     if(move_type == const.CASTLING):
         side = bb.line(sq_dest) == const.G
         self.board[bb.castling_rook_start_sq[self.playerTurn][side]] = const.ROOK* (-1 if self.playerTurn else 1)
         self.board[bb.castling_rook_dest_sq[self.playerTurn][side]] = 0
         self.figures[const.ROOK][self.playerTurn]  ^= bb.mask64[bb.castling_rook_dest_sq[self.playerTurn][side]] | bb.mask64[bb.castling_rook_start_sq[self.playerTurn][side]]
         
     self.refreshAllFigBitboard()
示例#5
0
    def updateHistoryList(self):
        self.gui.history_lb.delete(0, tk.END)

        # move = self.game.history[-1][0]

        for history_note in self.history:
            move = history_note[0]

            sq_start = bo.getBits(move, *const.MOVE_START)
            sq_dest = bo.getBits(move, *const.MOVE_DEST)
            fig_start = bo.getBits(move, *const.MOVE_FIG_START)
            fig_cap = bo.getBits(move, *const.MOVE_FIG_CAPTURE)
            fig_prom = bo.getBits(move, *const.MOVE_PROM) + 2
            move_type = bo.getBits(move, *const.MOVE_TYPE)
            color = bo.getBits(move, *const.MOVE_COLOR)

            rank_start = bb.rank(sq_start)
            rank_dest = bb.rank(sq_dest)

            line_start = bb.line(sq_start)
            line_dest = bb.line(sq_dest)

            comb_chr = "-"
            if fig_cap != 0:
                comb_chr = "x"

            suffix = ""
            if move_type == const.PROMOTION:
                suffix = " =" + const.ASCII_FIG[color][fig_prom]
            history_entry = "%c%c%i%c%c%i%s" % (
                const.ASCII_FIG[color][fig_start],
                chr(97 + line_start),
                rank_start + 1,
                comb_chr,
                chr(97 + line_dest),
                rank_dest + 1,
                suffix,
            )

            self.gui.addToHistory(history_entry)
示例#6
0
    def doMove(self, move):
        sq_start = bo.getBits(move, *const.MOVE_START)
        sq_dest = bo.getBits(move, *const.MOVE_DEST)
        
        fig_start = bo.getBits(move, *const.MOVE_FIG_START)
        fig_cap = bo.getBits(move, *const.MOVE_FIG_CAPTURE)
        
        fig_prom = bo.getBits(move, *const.MOVE_PROM) + 2
        
        move_type = bo.getBits(move, *const.MOVE_TYPE)
        color = bo.getBits(move, *const.MOVE_COLOR)
        
        #move on board
        self.board[sq_start] = 0
        self.board[sq_dest] = fig_start * (-1 if color else 1)
        
        #move source piece
        self.figures[fig_start][color] ^= bb.mask64[sq_start] 
        self.figures[fig_start][color] |= bb.mask64[sq_dest]
        
        #update king possition and castling rights
        if(fig_start == const.KING):
            self.king_pos[color] = sq_dest
        
        #remove captured piece
        if( fig_cap ):
            self.figures[fig_cap][not color] ^=  bb.mask64[sq_dest]
            self.material_value += aiv.MATERIAL_VALUE[fig_cap] * (-1 if color else 1)
        
        #special moves
        if(move_type == const.ENPASSANT_CAPTURE):
            self.board[sq_dest-8+16*color] = 0
            self.figures[const.PAWN][not color] ^= bb.pawn_singlestep[not color][sq_dest]
            self.material_value += aiv.MATERIAL_VALUE[const.PAWN] * (-1 if color else 1)
        if(move_type == const.PROMOTION):
            self.board[sq_dest] = fig_prom* (-1 if color else 1)
            self.figures[fig_prom][color] |= bb.mask64[sq_dest]
            self.figures[const.PAWN][color] ^= bb.mask64[sq_dest]
            self.material_value += (aiv.MATERIAL_VALUE[fig_prom] - aiv.MATERIAL_VALUE[const.PAWN]) * (-1 if color else 1)
        if(move_type == const.CASTLING):
            side = bb.line(sq_dest) == const.G
            self.board[bb.castling_rook_start_sq[color][side]] = 0
            self.board[bb.castling_rook_dest_sq[color][side]] = const.ROOK* (-1 if color else 1)
            self.figures[const.ROOK][color] ^= bb.mask64[bb.castling_rook_dest_sq[color][side]] | bb.mask64[bb.castling_rook_start_sq[color][side]]

        self.history.append( (move, copy.deepcopy(self.note)) )

        #update note
        self.note[0] = 0  #remove en-passant note
        if(move_type == const.DOUBLE_STEP):
            self.note[0] |= bb.mask8[bb.line(sq_start)]
            
        #castling rights
        if(fig_start == const.KING):
            self.note[1][color] = [1,1]
        if(fig_start == const.ROOK):
            for side in (const.CASTLING_LEFT, const.CASTLING_RIGHT):
                if(bb.castling_rook_start_sq[color][side] == sq_start):
                    self.note[1][color][side] = 1
        
        #fifty-move-rule
        if(fig_start != const.PAWN and fig_cap == 0):
            self.note[2] += 1
        else:
            self.note[2] = 0
            
        #move counter
        self.note[3] += 1

        self.refreshAllFigBitboard()
        self.playerTurn = not color
示例#7
0
    def doMove(self, move):
        sq_start = bo.getBits(move, *const.MOVE_START)
        sq_dest = bo.getBits(move, *const.MOVE_DEST)

        fig_start = bo.getBits(move, *const.MOVE_FIG_START)
        fig_cap = bo.getBits(move, *const.MOVE_FIG_CAPTURE)

        fig_prom = bo.getBits(move, *const.MOVE_PROM) + 2

        move_type = bo.getBits(move, *const.MOVE_TYPE)
        color = bo.getBits(move, *const.MOVE_COLOR)

        #move on board
        self.board[sq_start] = 0
        self.board[sq_dest] = fig_start * (-1 if color else 1)

        #move source piece
        self.figures[fig_start][color] ^= bb.mask64[sq_start]
        self.figures[fig_start][color] |= bb.mask64[sq_dest]

        #update king possition and castling rights
        if (fig_start == const.KING):
            self.king_pos[color] = sq_dest

        #remove captured piece
        if (fig_cap):
            self.figures[fig_cap][not color] ^= bb.mask64[sq_dest]
            self.material_value += aiv.MATERIAL_VALUE[fig_cap] * (-1 if color
                                                                  else 1)

        #special moves
        if (move_type == const.ENPASSANT_CAPTURE):
            self.board[sq_dest - 8 + 16 * color] = 0
            self.figures[const.PAWN][not color] ^= bb.pawn_singlestep[
                not color][sq_dest]
            self.material_value += aiv.MATERIAL_VALUE[const.PAWN] * (
                -1 if color else 1)
        if (move_type == const.PROMOTION):
            self.board[sq_dest] = fig_prom * (-1 if color else 1)
            self.figures[fig_prom][color] |= bb.mask64[sq_dest]
            self.figures[const.PAWN][color] ^= bb.mask64[sq_dest]
            self.material_value += (aiv.MATERIAL_VALUE[fig_prom] -
                                    aiv.MATERIAL_VALUE[const.PAWN]) * (
                                        -1 if color else 1)
        if (move_type == const.CASTLING):
            side = bb.line(sq_dest) == const.G
            self.board[bb.castling_rook_start_sq[color][side]] = 0
            self.board[bb.castling_rook_dest_sq[color]
                       [side]] = const.ROOK * (-1 if color else 1)
            self.figures[const.ROOK][color] ^= bb.mask64[
                bb.castling_rook_dest_sq[color][side]] | bb.mask64[
                    bb.castling_rook_start_sq[color][side]]

        self.history.append((move, copy.deepcopy(self.note)))

        #update note
        self.note[0] = 0  #remove en-passant note
        if (move_type == const.DOUBLE_STEP):
            self.note[0] |= bb.mask8[bb.line(sq_start)]

        #castling rights
        if (fig_start == const.KING):
            self.note[1][color] = [1, 1]
        if (fig_start == const.ROOK):
            for side in (const.CASTLING_LEFT, const.CASTLING_RIGHT):
                if (bb.castling_rook_start_sq[color][side] == sq_start):
                    self.note[1][color][side] = 1

        #fifty-move-rule
        if (fig_start != const.PAWN and fig_cap == 0):
            self.note[2] += 1
        else:
            self.note[2] = 0

        #move counter
        self.note[3] += 1

        self.refreshAllFigBitboard()
        self.playerTurn = not color