public SquareNode(BoardNode board, Piece.Colour colour, Position position) { Board = board; Colour = colour; Position = position; }
public PieceDrawer(BoardNode board) { Board = board; Board.WhitePlayer.MoveFromSelected += MoveFromSelected; Board.BlackPlayer.MoveFromSelected += MoveFromSelected; }
public override void _Ready() { Rect = new ColorRect(); AddChild(Rect); Rect.Color = Colour == Piece.Colour.White ? WhiteColour : BlackColour; Rect.RectSize = new Vector2(SquareSize, SquareSize); var pos = BoardNode.ScreenCoords(Position); Rect.RectPosition = pos; }
public override void _Ready() { Board = GetParent <BoardNode>(); Board.Checkmate += OnCheckmate; Board.Stalemate += OnStalemate; PromotionUI = GetNode <PromotionUI>("Promotion"); GetNode <Button>("Checkmate/Menu").Connect("pressed", this, nameof(Menu)); GetNode <Button>("Stalemate/Menu").Connect("pressed", this, nameof(Menu)); }
public HumanPlayer(BoardNode board, Piece.Colour colour) : base(board, colour) { SquareClickedTcs = new TaskCompletionSource <Position>(); board.SquareClicked += p => { if (Board.CurrentPlayer != Colour) { return; } SquareClickedTcs.SetResult(p); SquareClickedTcs = new TaskCompletionSource <Position>(); }; }
private void DrawPieces() { for (int i = 0; i < Chess.Board.Size; i++) { for (int j = 0; j < Chess.Board.Size; j++) { var position = new Position(j, i); if (Board.Board[position] is Piece piece) { DrawTexture(PieceTexture(piece), BoardNode.ScreenCoords(position)); } } } }
public override void _Ready() { Board = GetParent <UI>().GetParent <BoardNode>(); Tcs = new TaskCompletionSource <Piece.PieceType>(); Rook = GetNode <TextureButton>("Choices/Rook"); Knight = GetNode <TextureButton>("Choices/Knight"); Bishop = GetNode <TextureButton>("Choices/Bishop"); Queen = GetNode <TextureButton>("Choices/Queen"); Rook.Connect("pressed", this, nameof(RookChosen)); Knight.Connect("pressed", this, nameof(KnightChosen)); Bishop.Connect("pressed", this, nameof(BishopChosen)); Queen.Connect("pressed", this, nameof(QueenChosen)); }
private Player CreatePlayer(PlayerTypeSelector.PlayerType type, BoardNode board, Piece.Colour colour) { switch (type) { case PlayerTypeSelector.PlayerType.Human: return(new HumanPlayer(board, colour)); case PlayerTypeSelector.PlayerType.Computer: return(new AIPlayer(board, colour)); case PlayerTypeSelector.PlayerType.Random: return(new RandomPlayer(board, colour)); default: throw new ApplicationException($"Invalid player type {type}"); } }
private void VisualiseMoves() { if (MoveFrom.HasValue) { DrawRect(new Rect2(BoardNode.ScreenCoords(MoveFrom.Value), new Vector2(SquareNode.SquareSize, SquareNode.SquareSize)), Colors.Blue); } if (Board.LegalMoves != null) { foreach (var move in Board.LegalMoves.Where(m => m.From == MoveFrom)) { var colour = Colors.Limegreen; if (Board.Board[move.To].HasValue) { colour = Colors.Red; } DrawRect(new Rect2(BoardNode.ScreenCoords(move.To), new Vector2(SquareNode.SquareSize, SquareNode.SquareSize)), colour); } } }
protected Player(BoardNode board, Piece.Colour colour) { Board = board; Colour = colour; }
public RandomPlayer(BoardNode board, Piece.Colour colour) : base(board, colour) { Random = new Random(); }
public AIPlayer(BoardNode board, Piece.Colour colour) : base(board, colour) { MoveChooser = new MoveChooser(colour); Constants = AIConstants.Default; }