Skip to content

Commit

Permalink
Transposition table hash memory now adjustable (and not infinite), wi…
Browse files Browse the repository at this point in the history
…th UCI option support

Add cutnodes and internal iterative deepening to search

Additional evaluation terms

Stop init MoveStack and PieceStack with undefs as was leading to out of bounds errors in cmtable
  • Loading branch information
Jeremy committed Jan 17, 2020
1 parent d68239c commit 579a0d1
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/transposition2.jl
deps/tbprobe.so
deps/config.jl
deps/build.log
builddir/
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Astellarn"
uuid = "f591c62c-242e-4069-a3ea-9f76b695a940"
authors = ["Jeremy Revell"]
version = "0.2.1"
version = "0.2.2"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down
2 changes: 1 addition & 1 deletion src/Astellarn.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Astellarn
const ASTELLARN_VERSION = "v0.2.1"
const ASTELLARN_VERSION = "v0.2.2"

using Crayons
using StaticArrays
Expand Down
5 changes: 4 additions & 1 deletion src/AstellarnEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
using Astellarn

# start the uci loop
uci_main()
Base.@ccallable function julia_main()::Cint
uci_main()
return 0
end
13 changes: 13 additions & 0 deletions src/bitboard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ A bitboard representing the central files of a board.
const CENTERFILES = FILE_C | FILE_D | FILE_E | FILE_F


"""
CENTRAL_SQUARES
A bitboard representing the central 4 squares of a board.
"""
const CENTRAL_SQUARES = (RANK_4 | RANK_5) & (FILE_D | FILE_E)


"""
KINGFLANK
Expand All @@ -465,6 +473,11 @@ const KINGFLANK = @SVector [QUEENSIDE ⊻ FILE_D, QUEENSIDE, QUEENSIDE,
CENTERFILES, CENTERFILES, KINGSIDE, KINGSIDE, KINGSIDE FILE_E]


distance(sqr1::Int, sqr2::Int) = max(abs(fileof(sqr1) - fileof(sqr2)), abs(rankof(sqr1) - rankof(sqr2)))

const DISTANCE_BETWEEN = [distance(sqr1, sqr2) for sqr1 in 1:64, sqr2 in 1:64]


# Custom show for bitboard types
function Base.show(io::IO, bb::Bitboard)
println(io, "Bitboard:")
Expand Down
40 changes: 31 additions & 9 deletions src/board.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ friendly(board::Board) = @inbounds board[board.turn]
Return the positions, as a `Bitboard`, of all the occupied squares on the board.
"""
occupied(board::Board) = @inbounds board[WHITE] | board[BLACK]
occupied(board::Board) = white(board) | black(board)


"""
Expand Down Expand Up @@ -225,52 +225,67 @@ function Base.show(io::IO, board::Board)
end


"""
white(board::Board)
Get the location of all the white pieces on the board, as a `Bitboard`.
"""
white(board::Board) = @inbounds board.colors[1]


"""
black(board::Board)
Get the location of all the black pieces on the board, as a `Bitboard`.
"""
black(board::Board) = @inbounds board.colors[2]

"""
pawns(board::Board)
Get the location of all the pawns on the `board`, as a `Bitboard`.
"""
pawns(board::Board) = @inbounds board[PAWN]
pawns(board::Board) = @inbounds board.pieces[1]


"""
knights(board::Board)
Get the location of all the knights on the `board`, as a `Bitboard`.
"""
knights(board::Board) = @inbounds board[KNIGHT]
knights(board::Board) = @inbounds board.pieces[2]


"""
bishops(board::Board)
Get the location of all the bishops on the `board`, as a `Bitboard`.
"""
bishops(board::Board) = @inbounds board[BISHOP]
bishops(board::Board) = @inbounds board.pieces[3]


"""
rooks(board::Board)
Get the location of all the rooks on the `board`, as a `Bitboard`.
"""
rooks(board::Board) = @inbounds board[ROOK]
rooks(board::Board) = @inbounds board.pieces[4]


"""
queens(board::Board)
Get the location of all the queens on the `board`, as a `Bitboard`.
"""
queens(board::Board) = @inbounds board[QUEEN]
queens(board::Board) = @inbounds board.pieces[5]


"""
kings(board::Board)
Get the location of all the kings on the `board`, as a `Bitboard`.
"""
kings(board::Board) = @inbounds board[KING]
kings(board::Board) = @inbounds board.pieces[6]


"""
Expand Down Expand Up @@ -338,7 +353,14 @@ cancastlequeenside(board::Board, color::Color) = isone((board.castling >> (color
cancastlequeenside(board::Board) = cancastlequeenside(board, board.turn)


# is the position legal
"""
has_non_pawn_material(board::Board)
Check if a position has non-pawn material left.
"""
has_non_pawn_material(board::Board) = !isempty(knights(board)) || !isempty(bishops(board)) || !isempty(rooks(board)) || !isempty(queens(board))


"""
islegal(board::Board)
Expand Down Expand Up @@ -413,7 +435,7 @@ end
Detects draws by insufficient material. Returns `true` if the position is drawn.
"""
function isdrawbymaterial(board::Board)
piece_count = count(board[WHITE]) + count(board[BLACK])
piece_count = count(white(board)) + count(black(board))
if piece_count == 2
return true
elseif piece_count == 3
Expand Down
Loading

0 comments on commit 579a0d1

Please sign in to comment.