Skip to content

Commit

Permalink
Added Raylib, Raylib-cs credits, fixed one-in-a-trillion crash issue …
Browse files Browse the repository at this point in the history
…that happened
  • Loading branch information
Sargates authored and Sargates committed Aug 15, 2023
1 parent 1bcc6a7 commit c50cc23
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
6 changes: 4 additions & 2 deletions license.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
MIT License

Copyright (c) 2023 Nicholas Glenn
Credits to Yaroslav Bondarev (Stockfish.NET) (https://github.com/Oremiro/Stockfish.NET)
Copyright (c) 2023 Nicholas Glenn\
Credits to Ramon Santamaria (Raylib) (2013-2023) (https://github.com/raysan5/raylib)\
Credits to ChrisDill (Raylib-cs) (2018-2023) (https://github.com/ChrisDill/Raylib-cs/)\
Credits to Yaroslav Bondarev (Stockfish.NET) (2020) (https://github.com/Oremiro/Stockfish.NET)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 5 additions & 1 deletion src/Application/Core/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void MakeMove(Move move, bool animate=true) {
throw new Exception("Null move was played");
}

// view.ui.DeselectActiveSquare();
model.ActivePlayer.IsSearching = false;


Expand Down Expand Up @@ -135,7 +136,10 @@ public void MakeMove(Move move, bool animate=true) {
}

// If opponent can't respond, fallthrough to game end handling
if (canOpponentRespond) return;
if (canOpponentRespond) {
if (view.ui.selectedIndex!=-1) view.ui.movesForSelected = MoveGenerator.GetMoves(model.board, view.ui.selectedIndex);
return;
}

model.SuspendPlay = true;

Expand Down
22 changes: 12 additions & 10 deletions src/Engine/Move Generation/MoveGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ public static List<Move> GetPawnMoves(Board board, int index) {
Coord coord = new Coord(index);
Coord delta = new Coord(board.forwardDir(piece.Color));
Coord newPos = coord+delta;
Piece pawnOneUp = board.GetSquare(newPos.SquareIndex);
if (newPos.IsInBounds() && pawnOneUp == Piece.None) {
moves.Add(new Move(index, newPos.SquareIndex, (BoardHelper.RankIndex(index) == (piece.Color == Piece.White ? 6 : 1)) ? Move.PromoteToQueenFlag : Move.NoFlag));

if (BoardHelper.RankIndex(index) == (piece.Color == Piece.White ? 1 : 6) && board.GetSquare(index + 2*board.forwardDir(piece.Color)) == Piece.None) {
moves.Add(new Move(index, index + 2*board.forwardDir(piece.Color), Move.PawnTwoUpFlag));
if (newPos.IsInBounds()) {
Piece pawnOneUp = board.GetSquare(newPos.SquareIndex);
if (pawnOneUp == Piece.None) {
moves.Add(new Move(index, newPos.SquareIndex, (BoardHelper.RankIndex(index) == (piece.Color == Piece.White ? 6 : 1)) ? Move.PromoteToQueenFlag : Move.NoFlag));

if (BoardHelper.RankIndex(index) == (piece.Color == Piece.White ? 1 : 6) && board.GetSquare(index + 2*board.forwardDir(piece.Color)) == Piece.None) {
moves.Add(new Move(index, index + 2*board.forwardDir(piece.Color), Move.PawnTwoUpFlag));
}
}
}

delta = new Coord(+1, Math.Sign(board.forwardDir(piece.Color)));
newPos = coord+delta;
Piece pawnAttackPositive = board.GetSquare(newPos.SquareIndex);
if (newPos.IsInBounds()) {
Piece pawnAttackPositive = board.GetSquare(newPos.SquareIndex);
if ((pawnAttackPositive.Type != Piece.None) && pawnAttackPositive.Color != piece.Color ) {
moves.Add(new Move(index, newPos.SquareIndex, (BoardHelper.RankIndex(index) == (piece.Color == Piece.White ? 6 : 1)) ? Move.PromoteToQueenFlag : Move.NoFlag));
} else if ((newPos.SquareIndex == board.enPassantIndex && board.GetSquare(index + 1) != piece.Color)) {
Expand All @@ -43,8 +45,8 @@ public static List<Move> GetPawnMoves(Board board, int index) {

delta = new Coord(-1, Math.Sign(board.forwardDir(piece.Color)));
newPos = coord+delta;
Piece pawnAttackNegative = board.GetSquare(newPos.SquareIndex);
if (newPos.IsInBounds()) {
Piece pawnAttackNegative = board.GetSquare(newPos.SquareIndex);
if ((pawnAttackNegative.Type != Piece.None) && pawnAttackNegative.Color != piece.Color ) {
moves.Add(new Move(index, newPos.SquareIndex, (BoardHelper.RankIndex(index) == (piece.Color == Piece.White ? 6 : 1)) ? Move.PromoteToQueenFlag : Move.NoFlag));
} else if ((newPos.SquareIndex == board.enPassantIndex && board.GetSquare(index - 1) != piece.Color)) {
Expand All @@ -61,9 +63,9 @@ public static List<Move> GetPawnMoves(Board board, int index) {
// Edge case in enpassant capture
// See: https://www.chessprogramming.org/Perft_Results#cite_note-9:~:text=8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8
if (move.MoveFlag == Move.EnPassantCaptureFlag) {
// If the move is en-passant capture, then we need to check if the king would be in check after the move,
// If the move is en-passant capture, then we need to check if the king would be in check after the move,
// if the colorToMove's king is in the same file as both pawns and say a rook, en-passant capture would be illegal,
// We need to cache the piece that's taken, and check if the pawn that gets moved is pinned,
// We need to cache the piece that's taken, remove it from the board, and check if the pawn to move is pinned by an enemy piece,

int enemyPawnIndex = board.enPassantIndex - board.forwardDir(piece.Color);
Piece enemyPawn = board.board[enemyPawnIndex];
Expand Down

0 comments on commit c50cc23

Please sign in to comment.