A chess library for Gleam

Use stockfish piece values

Changed files
+24 -23
src
+8 -6
src/starfish/internal/board.gleam
··· 34 34 King 35 35 } 36 36 37 - pub const pawn_value = 100 37 + // Values taken from https://hxim.github.io/Stockfish-Evaluation-Guide/ 38 38 39 - pub const knight_value = 300 39 + pub const pawn_value = 124 40 40 41 - pub const bishop_value = 300 41 + pub const knight_value = 781 42 42 43 - pub const rook_value = 500 43 + pub const bishop_value = 825 44 44 45 - pub const queen_value = 900 45 + pub const rook_value = 1276 46 + 47 + pub const queen_value = 2538 46 48 47 - pub const king_value = 1000 49 + pub const king_value = 10_000 48 50 49 51 pub fn piece_value(piece: Piece) -> Int { 50 52 case piece {
+15 -16
src/starfish/internal/game.gleam
··· 494 494 pub fn is_insufficient_material(game: Game) -> Bool { 495 495 game.black_pieces.pawn_material == 0 496 496 && game.white_pieces.pawn_material == 0 497 - && { 498 - game.black_pieces.non_pawn_material == board.bishop_value 499 - || game.black_pieces.non_pawn_material == board.knight_value 500 - || game.black_pieces.non_pawn_material == 0 501 - } 502 - && { 503 - game.white_pieces.non_pawn_material == board.bishop_value 504 - || game.white_pieces.non_pawn_material == board.knight_value 505 - || game.white_pieces.non_pawn_material == 0 506 - } 497 + && game.black_pieces.non_pawn_material <= board.bishop_value 498 + && game.white_pieces.non_pawn_material <= board.bishop_value 507 499 } 508 500 509 501 pub fn is_threefold_repetition(game: Game) -> Bool { ··· 532 524 533 525 const phase_multiplier = 128 534 526 535 - /// About queen + rook, so one major piece per side 536 - const endgame_material = 1400 527 + // Values taken from https://hxim.github.io/Stockfish-Evaluation-Guide/ 528 + 529 + /// About queen + rook, so one major piece per side. If total material is less 530 + /// than this, then we are completely in the endgame. 531 + const endgame_material = 3915 537 532 538 - /// Below this material limit, the endgame weight is zero. this is about enough 539 - /// for three minor pieces to be captured. 540 - const middlegame_material = 3000 533 + /// Above this material limit, the endgame weight is zero. this is about enough 534 + /// for three minor pieces to be captured . 535 + const middlegame_material = 15_258 541 536 542 537 pub fn phase(game: Game) -> Int { 543 538 let non_pawn_material = ··· 590 585 piece_square_score_midgame:, 591 586 piece_square_score_endgame:, 592 587 ) = pieces 588 + 589 + // Pawns become much more valuable in the endgame, about 1.5x 590 + let pawn_material_endgame = pawn_material * 15 / 10 591 + 593 592 non_pawn_material 594 - + pawn_material 593 + + interpolate_phase(pawn_material, pawn_material_endgame, phase) 595 594 + interpolate_phase( 596 595 piece_square_score_midgame, 597 596 piece_square_score_endgame,
+1 -1
src/starfish/internal/piece_table.gleam
··· 6 6 7 7 import starfish/internal/board 8 8 9 - // Values taken from https://www.chessprogramming.org/Simplified_Evaluation_Function 9 + // Values taken from https://hxim.github.io/Stockfish-Evaluation-Guide/ 10 10 11 11 // We use tuples for constant time accessing. The values are constant so we don't 12 12 // need to worry about the cost of updating.