def main(): # Создаём шахматную доску board = Board() # Цикл ввода команд игроков while True: # Выводим положение фигур на доске print_board(board) # Подсказка по командам print('Команды:') print(' exit -- выход') print( ' move <row> <col> <row1> <col1> -- ход из клетки (row, col)' ) print( ' в клетку (row1, col1)') # Выводим приглашение игроку нужного цвета if board.current_player_color() == WHITE: print('Ход белых:') else: print('Ход черных:') command = input() if command == 'exit': break move_type, row, col, row1, col1 = command.split() row, col, row1, col1 = int(row), int(col), int(row1), int(col1) if board.move_piece(row, col, row1, col1): print('Ход успешен') else: print('Координаты некорректы! Попробуйте другой ход!')
def train(N, W, B): w = 0 bl = 0 d = 0 for i in range(N): b = Board() #print("#####Game" + str(i + 1) + "#####") res, W, B = startGame(W, B, b) #print("#####Game" + str(i + 1) + " Over#####") if i%50 == 0 and i != 0: W.decayEps(0.75) B.decayEps(0.75) if res == 1: print("### WHITE WON GAME " + str(i+1) + " ###") print() w += 1 elif res == -1: print("### BLACK WON GAME " + str(i+1) + " ###") print() bl += 1 else: print("### DRAW GAME " + str(i+1) + " ###") print() d +=1 print("White wins: " + str(w)) print("Black wins: " + str(bl)) print("Draws: " + str(d)) return W, B
def play(B): n = 1 b = Board() while n: b.showBoard() moves = b.generateMoveStrings() print(moves) while True: move = input("Enter move:") #b.showBoard() if move in moves: b.makeMove(move) break if b.isCheckMate(): b.showBoard() b.unMove() B.getReward(0) B.resetState() b = Board() n = int(input("Play again (1/0) :")) if n == 0: break else: continue if b.isDraw(): b.showBoard() b.unMove() W.getReward(0.3) W.resetState() B.getReward(0.4) B.resetState() b = Board() n = int(input("Play again (1/0) :")) if n == 0: break B.makeMove(b) #b.showBoard() if b.isCheckMate(): b.showBoard() B.getReward(1) B.resetState() b = Board() n = int(input("Play again (1/0) :")) if b.isDraw(): b.showBoard() B.getReward(0.4) B.resetState() b = Board() n = int(input("Play again (1/0) :"))
from ChessPiece import Piece from ChessBoard import Board board1 = Board() board1.make_board() class Horse(Piece): #inititalizing pieces and return def __init__(self, piece, colour, startx, starty, img): super().__init__(piece, colour, startx, starty, img) #method checking and giving all valid moves def valid_moves(self, board): x = self.startx y = self.starty moves = [] #topside right if x < 6 and y > 0: if not board.has_piece(x + 2, y - 1): moves.append([x + 2, y - 1]) else: if board.which_piece(x + 2, y - 1).colour != self.colour: moves.append([x + 2, y - 1]) else: pass #top right diagnol if x < 7 and y > 1: if not board.has_piece(x + 1, y - 2): moves.append([x + 1, y - 2]) else: if board.which_piece(x + 1, y - 2).colour != self.colour:
self.gameEnv.screen.endScreen() if self.board.isDraw(): print("Draw.") b.unMove() self.gameEnv.screen.endScreen() self.setBoard() else: self.start.blackMove(self.b_agent, 3) if self.board.isCheckMate(): print("Black won.") b.unMove() self.gameEnv.screen.endScreen() if self.board.isDraw(): print("Draw.") b.unMove() self.gameEnv.screen.endScreen() self.setBoard() move += 1 self.gameEnv.screen.displayScreen() self.gameEnv.screen.clockTick() gameEnv = gil.GameEnv(30, (400, 400)) W = agent.ABAgent(agent.WHITE) B = agent.ABAgent(agent.BLACK) b = Board() chess = Chess(W, B, b, gameEnv) chess.initBoard()
def play(self, B): #black agent n = 1 b = Board() while n: b.showBoard() moves = b.generateMoveStrings() print(moves) while True: move = input("Enter move:") #b.showBoard() if move in moves: b.makeMove(move) break if b.isCheckMate(): b.showBoard() b.unMove() b = Board() n = int(input("Play again (1/0) :")) if n == 0: break else: continue if b.isDraw(): b.showBoard() b.unMove() b = Board() n = int(input("Play again (1/0) :")) if n == 0: break B.makeMoveUtil(b, 1) #b.showBoard() if b.isCheckMate(): b.showBoard() b = Board() n = int(input("Play again (1/0) :")) if b.isDraw(): b.showBoard() b = Board() n = int(input("Play again (1/0) :"))