public CheckersWindow() { this.InitializeComponent(); board = new CheckersBoard(0, x); board.GameMaxLength = 150; lastMove = new CheckersMove(null, false, 1); moveList.Tag = new List<CheckersMove>(); myRepaint = new Repaint(this.repaint); CheckersPlayer player = new CheckersPlayer(ComputerPlayer); alg = new Algorithms(player); int blackWhite = 1; for (int row = 0; row < 8; ++row) { for (int col = 0; col < 8; ++col) { if (blackWhite % 2 == 0) { BlackSquare square = new BlackSquare(); square.SetValue(Grid.ColumnProperty, col); square.SetValue(Grid.RowProperty, row); square.Tag = new System.Windows.Point(row, col); square.DragEnter += new DragEventHandler(square_DragEnter); square.Drop += new DragEventHandler(square_Drop); square.MouseLeftButtonDown += new MouseButtonEventHandler(square_MouseLeftButtonDown); UIBoard.Children.Add(square); blackSquares.Add(square); } else { WhiteSquare square = new WhiteSquare(); square.SetValue(Grid.ColumnProperty, col); square.SetValue(Grid.RowProperty, row); UIBoard.Children.Add(square); } blackWhite++; } blackWhite++; } StringBuilder stringBuilder = new StringBuilder("Current Player is:\n"); stringBuilder.Append(board.GetCurrentPlayer().GetPlayerID().ToString() == "-1" ? "Black" : "White"); currentPlayerLabel.Content = stringBuilder.ToString(); repaint(null); board.GameOver += new CheckersBoard.EndGame(board_GameOver); if (board.GetCurrentPlayer().GetPlayerID() == alg.ComputerPlayerID) { computerThread = new Thread(this.computerMove); computerThread.Start(); } this.visualGameOver = new EndGame(this.theGameIsOver); }
public CheckersBoard(int player, double[] weights) { if (player != 0 && player != 1) throw new ArgumentException("Value must be 0 or 1"); this.gameBoard = new int[8, 8]; this.whiteKingcount = 0; this.whitePieceCount = 12; this.blackKingCount = 0; this.blackPieceCount = 12; this.players = new CheckersPlayer[2]; this.players[1] = new CheckersPlayer(1); this.players[0] = new CheckersPlayer(-1); this.currentPlayer = players[player]; this.SetForNewGame(); this.weights = new double[weights.Length]; for (int index = 0; index < this.weights.Length; ++index) this.weights[index] = weights[index]; this.GameOver += new EndGame(calculateWinner); this.GameMaxLength = 200; }
public CheckersBoard(int[,] gameBoard, double[] weights, int player) { this.gameBoard = new int[8, 8]; this.players = new CheckersPlayer[2]; this.players[1] = new CheckersPlayer(1); this.players[0] = new CheckersPlayer(-1); this.currentPlayer = players[player]; this.weights = new double[weights.Length]; for (int index = 0; index < this.weights.Length; ++index) this.weights[index] = weights[index]; for (int row = 0; row < 8; ++row) for (int col = 0; col < 8; ++col) { this.gameBoard[row, col] = gameBoard[row, col]; } this.updateLegalMoves(); this.updateCounters(); this.GameMaxLength = 200; this.GameOver += new EndGame(calculateWinner); }
public CheckersBoard(CheckersBoard board, bool isVisualBoard) { this.gameBoard = new int[8, 8]; this.players = new CheckersPlayer[2]; for (int row = 0; row < 8; ++row) for (int col = 0; col < 8; ++col) { this.gameBoard[row, col] = board.gameBoard[row, col]; } this.weights = new double[board.weights.Length]; for (int index = 0; index < this.weights.Length; ++index) this.weights[index] = board.weights[index]; this.players[1] = new CheckersPlayer(1); this.players[0] = new CheckersPlayer(-1); if (board.currentPlayer.GetPlayerID() == 1) this.currentPlayer = players[1]; else this.currentPlayer = players[0]; this.GameOver += new EndGame(calculateWinner); this.GameMaxLength = board.GameMaxLength; if (isVisualBoard) GameOver = board.GameOver; this.updateLegalMoves(); if (legalMoves.Count > 0) this.updateCounters(); }
public void SetForNewGame() { currentPlayer = players[0]; gameBoard = new int[8, 8]; gameBoard[0, 1] = CheckersBoard.WhitePiece; gameBoard[0, 3] = CheckersBoard.WhitePiece; gameBoard[0, 5] = CheckersBoard.WhitePiece; gameBoard[0, 7] = CheckersBoard.WhitePiece; gameBoard[1, 0] = CheckersBoard.WhitePiece; gameBoard[1, 2] = CheckersBoard.WhitePiece; gameBoard[1, 4] = CheckersBoard.WhitePiece; gameBoard[1, 6] = CheckersBoard.WhitePiece; gameBoard[2, 1] = CheckersBoard.WhitePiece; gameBoard[2, 3] = CheckersBoard.WhitePiece; gameBoard[2, 5] = CheckersBoard.WhitePiece; gameBoard[2, 7] = CheckersBoard.WhitePiece; gameBoard[5, 0] = CheckersBoard.BlackPiece; gameBoard[5, 2] = CheckersBoard.BlackPiece; gameBoard[5, 4] = CheckersBoard.BlackPiece; gameBoard[5, 6] = CheckersBoard.BlackPiece; gameBoard[6, 1] = CheckersBoard.BlackPiece; gameBoard[6, 3] = CheckersBoard.BlackPiece; gameBoard[6, 5] = CheckersBoard.BlackPiece; gameBoard[6, 7] = CheckersBoard.BlackPiece; gameBoard[7, 0] = CheckersBoard.BlackPiece; gameBoard[7, 2] = CheckersBoard.BlackPiece; gameBoard[7, 4] = CheckersBoard.BlackPiece; gameBoard[7, 6] = CheckersBoard.BlackPiece; this.updateLegalMoves(); this.updateCounters(); }
public void ChangePlayer() { if (currentPlayer.GetPlayerID() == 1) currentPlayer = players[0]; else { currentPlayer = players[1]; } this.updatePieces(); this.updateLegalMoves(); this.updateCounters(); }