mirror of
https://github.com/tiyn/yeschess.git
synced 2025-04-01 14:47:44 +02:00
visibility: use include in tests and only set needed functions as public
This commit is contained in:
parent
10098da82f
commit
b3c76fd2c1
@ -6,7 +6,7 @@ type
|
||||
## `Color` describes the possible color of players.
|
||||
Black = -1,
|
||||
White = 1
|
||||
Board* = array[0..119, int] ## \
|
||||
Board = array[0..119, int] ## \
|
||||
## `Board` saves the position of the chess pieces.
|
||||
CastleRights = tuple
|
||||
## `CastleRights` contains the rights to castling for each player.
|
||||
@ -24,8 +24,8 @@ type
|
||||
castleRights: CastleRights
|
||||
Move* = object
|
||||
## `Move` stores all important information for a move.
|
||||
start*: int
|
||||
dest*: int
|
||||
start: int
|
||||
dest: int
|
||||
color: Color
|
||||
prom: int
|
||||
PieceAmount = tuple
|
||||
@ -39,7 +39,7 @@ type
|
||||
Pieces = array[10,int]
|
||||
|
||||
const
|
||||
Block* = 999 ## \
|
||||
Block = 999 ## \
|
||||
## `Block` is the value assigned to empty blocked fields in a board.
|
||||
WPawn* = 1
|
||||
## `WPawn` is the value assigned to a square in a board with a white pawn.
|
||||
@ -54,9 +54,9 @@ const
|
||||
WQueen* = 5 ## \
|
||||
## `WQueen` is the value assigned to a square in a board with a white
|
||||
## queen.
|
||||
WKing* = 6 ## \
|
||||
WKing = 6 ## \
|
||||
## `WKing` is the value assigned to a square in a board with a white king.
|
||||
WEnPassant* = 7 ## \
|
||||
WEnPassant = 7 ## \
|
||||
## `WEnPassant` is assigned to a square in a board with an invisible white
|
||||
## en passant pawn.
|
||||
BPawn* = -WPawn ## \
|
||||
@ -71,9 +71,9 @@ const
|
||||
## `BRook` is the value assigned to a square in a board with a black rook.
|
||||
BQueen* = -WQueen ## \
|
||||
## `BQueen` is the value assigned to a square in a board with a black queen.
|
||||
BKing* = -WKing ## \
|
||||
BKing = -WKing ## \
|
||||
## `BKing` is the value assigned to a square in a board with a black king.
|
||||
BEnPassant* = -WEnPassant ## \
|
||||
BEnPassant = -WEnPassant ## \
|
||||
## `BEnPassant` is assigned to a square in a board with an invisible black
|
||||
## en passant pawn.
|
||||
N = 10 ## `N` describes a move a field up the board from whites perspective.
|
||||
@ -142,7 +142,7 @@ let
|
||||
# `FileChar` maps the files of the chessboard to numbers for better
|
||||
# conversion.
|
||||
|
||||
proc fieldToInd*(field: string): int =
|
||||
proc fieldToInd(field: string): int =
|
||||
## Calculate and return board index from `field` of a chess board.
|
||||
## Returns -1 if the `field` was not input correct.
|
||||
try:
|
||||
@ -152,7 +152,7 @@ proc fieldToInd*(field: string): int =
|
||||
except IndexDefect, ValueError:
|
||||
return -1
|
||||
|
||||
proc indToField*(ind: int): string =
|
||||
proc indToField(ind: int): string =
|
||||
## Calculate and returns field name from board index `ind`.
|
||||
let line = (int)ind/10-1
|
||||
let file_ind = 7-((ind)%%10-1)
|
||||
@ -160,7 +160,7 @@ proc indToField*(ind: int): string =
|
||||
if FileChar[file] == file_ind:
|
||||
return $file & $line
|
||||
|
||||
proc getMove*(start: int, dest: int, prom: int, color: Color): Move =
|
||||
proc getMove(start: int, dest: int, prom: int, color: Color): Move =
|
||||
## Get a move object of the `color` player from `start` to `dest` with an
|
||||
## eventual promition to `prom`.
|
||||
var move = Move(start: start, dest: dest, prom: prom * ord(color), color: color)
|
||||
@ -168,7 +168,7 @@ proc getMove*(start: int, dest: int, prom: int, color: Color): Move =
|
||||
move.prom = WQueen
|
||||
return move
|
||||
|
||||
proc getMove*(start: int, dest: int, color: Color): Move =
|
||||
proc getMove(start: int, dest: int, color: Color): Move =
|
||||
## Get a move object of the `color` player from `start` to `dest` with
|
||||
## automatic promition to queen.
|
||||
var move = Move(start: start, dest: dest, prom: WQueen * ord(color), color: color)
|
||||
@ -259,7 +259,7 @@ proc initChess*(): Chess =
|
||||
fiftyMoveCounter: 0, castleRights: (true, true, true, true))
|
||||
return chess
|
||||
|
||||
proc initChess*(board: array[0..63, int], color: Color): Chess =
|
||||
proc initChess(board: array[0..63, int], color: Color): Chess =
|
||||
## Create and return a Chess object based on a position of choice.
|
||||
## `board` describes the pieces, `color` the color that is about to move.
|
||||
let board = initBoard(board)
|
||||
@ -533,7 +533,7 @@ proc isAttacked(chess: Chess, position: int, color: Color): bool =
|
||||
color), WKnight)
|
||||
return attacked
|
||||
|
||||
proc isInCheck*(chess: Chess, color: Color): bool =
|
||||
proc isInCheck(chess: Chess, color: Color): bool =
|
||||
## Returns true if the king of a given `color` is in check in a `chess`.
|
||||
var king_pos: int
|
||||
for i in countup(0, chess.board.high):
|
||||
@ -663,7 +663,7 @@ proc genLegalKingMoves(chess: Chess, field: int, color: Color): seq[Move] =
|
||||
res.add(getMove(field, dest, color))
|
||||
return res
|
||||
|
||||
proc genLegalMoves*(chess: Chess, field: int, color: Color): seq[Move] =
|
||||
proc genLegalMoves(chess: Chess, field: int, color: Color): seq[Move] =
|
||||
## Generates all legal moves in a `chess` starting from `field` for a `color`.
|
||||
var legal_moves = newSeq[Move]()
|
||||
var target = ord(color) * chess.board[field]
|
||||
|
@ -1,7 +1,7 @@
|
||||
import einheit
|
||||
import algorithm
|
||||
|
||||
import ./chess.nim
|
||||
include ./chess.nim
|
||||
|
||||
testSuite ChessTest of TestSuite:
|
||||
|
||||
|
@ -17,7 +17,7 @@ const
|
||||
DrawVal = 0 ## `DrawVal` is the engines value for a draw.
|
||||
LoVal = -1000000 ## `LoVal` is a value always lower than any evaluation.
|
||||
|
||||
proc pieceEval*(chess: Chess): int =
|
||||
proc pieceEval(chess: Chess): int =
|
||||
## Returns the evaluation of existing pieces on the `board`
|
||||
var evaluation = DrawVal
|
||||
for square in chess.board:
|
||||
@ -63,7 +63,7 @@ proc evaluate(chess: Chess): int =
|
||||
evaluation = min(DrawVal, evaluation)
|
||||
return evaluation
|
||||
|
||||
proc spanMoveTree*(chess: Chess, depth: int): MoveTree =
|
||||
proc spanMoveTree(chess: Chess, depth: int): MoveTree =
|
||||
## Create and return a Movetree of a given `chess` with a given maximum `depth`.
|
||||
var mTree: MoveTree
|
||||
mTree.chess = chess
|
||||
@ -75,7 +75,7 @@ proc spanMoveTree*(chess: Chess, depth: int): MoveTree =
|
||||
mTree.children.add(spanMoveTree(tmpChess, depth-1))
|
||||
return mTree
|
||||
|
||||
proc negaMax*(mTree: MoveTree): int =
|
||||
proc negaMax(mTree: MoveTree): int =
|
||||
## Return the value of the root node of a given `MoveTree`
|
||||
if mTree.children == []:
|
||||
return mTree.chess.evaluate()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import einheit
|
||||
|
||||
import ./chess.nim
|
||||
import ./engine.nim
|
||||
include ./chess.nim
|
||||
include ./engine.nim
|
||||
|
||||
testSuite ChessTest of TestSuite:
|
||||
|
||||
|
@ -15,7 +15,7 @@ proc runGameHotseat*(): void =
|
||||
while not chess.checkedMove(notationToMove(move, chess.toMove)):
|
||||
move = readLine(stdin)
|
||||
chess.echoBoard(chess.toMove)
|
||||
if (chess.isDrawClaimable):
|
||||
if (chess.isDrawClaimable()):
|
||||
echo "Do you want to claim a draw? (y/N)"
|
||||
draw = readLine(stdin)
|
||||
if (draw == "y"):
|
||||
|
Loading…
x
Reference in New Issue
Block a user