View on
Charles MINC > Chess-ChessKit-ChessKit > Chess::ChessKit



Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  


Chess::ChessKit A set of program to translate chess notations and analyses game by moves count


Version 0.04


ChessKit is composed of:

note: TMN : Theoretical move number : it's the precise number of different valid moves at the disposal of the chess player having to play.


ChessKit is a set of programs and packages to translate any chess notation into another one. As a consequence we have to provide software that can validate pieces (or pawns) moves.

About chess theory somebody states that advantage belongs to the player who has the bigger number of moves. So, to help to verify and pursue the idea,routines for that purpose have been developped.


all the functions below here.

FUNCTIONS inside Chess::ChessKit::Board ^

$gmv{$piece}(row=>$somerow, col =>$somecolumn, mov=>$ref_array_of_mov, color=>$piece) ;

return in $ref_array_of_mov all the moves that $piece written like in FEN (for example 'N' for White Knight, 'n' for Black Knight and so on). ($somerow,$somecolumn) are the coordinates of the starting square. color is again $piece because all the Whites are in upper case and blacks in lower case.

$bd->bestmove ; print a list of the best moves in the sense of TMN

$bd->boardcopy($new_board) ; copy the position of board $bd to the other board $new_board

$diag=$bd->can_castling(roq=>$roq , status=>$ref_status, out=>$out) ; check if a king can castle according to $ref_status (updated by has_moved). Also, verify the king is not checked. $roq=(KK|QK|kk|qk) where the first letter design the side and the second the king color. $out=('yes'|'no') if $out is to 'yes' a message indicates which pieces give a check. Default is 'no'. This function return 'yes' or 'no'.

$bd->cantake(who=>$piece, where=>$some_square) ; return 'no' if not possible or the type of the piece that can be taken.

$bd->castling(couleur=>$couleur, side=>$side, status=>$ref_status, out=>$out) execute castling if can_castling return 'yes' or die with diagnostic. Parameters can take the following values:

$ref_status is the parameter already described above.
$out=('yes'|'no') transmit this data to can_castling which print which piece give a check. Default is 'no'.

my ($cnt_white,$cnt_black)=$bd->chessmovcnt scan the board and return the count of the valid moves for both Blacks and Whites. (used next program-maintain for backward compatibility

my %sum=$bd->chessmovcntint scan the board and return the set of squares of the valid moves for Blacks @{$sum{b}} and Whites @{$sum{w}}. We can retrieve the datas as before for the above routine by the following way:

        $cnt_white=@{$sum{w}} ;
        $cnt_black=@{$sum{b}} ;

Note: squares could be duplicated in the hash

$bd->chessview print the board on screen.

$bd->deletepiece($location) delete the piece at location $location that are the algebraic coordinate of a square.

$piece=$bd->getpiece($location) retrieve the type of piece at board location $location

has_moved(status=>$ref_status, ini=>$ini)> set the status of Rook and king to know if they are always at there original place. So this function must be called after every moves. $ini=('y'|'no') if this parameter is set to 'y' the status is reset. The default option is of course 'no'.

bd->is_shaked(king=>$king, out=>$out) Diagnose if a king is checked by returning 'yes' or "" $out conditional parameter for printing the result if equal 'y'

$bd=Board->new(); create the objet $bd of class Board.

$bd->print print the position of pieces: location and type

$bd->put($piece,$location) place a piece $piece on the chessboard at $location

$bd->startgame(%set_position) initialize the chessboard with %set_position. Default without argument is the usual chessboard starting game.

$bd->valid(mov=>$set_of move, valid=>$set, piece=>$piece) intermediate validation of moves. Use datas obtained from %gmv : $set_of_move for $piece. It returns $set , the moves restricted to the true board.

$bd->vldmov(valid=>$set, piece=>$piece, row=>>$row, col=>>$col, recur=>>$control) Final validation of moves, where all the rules of chessgame are taken under consideration. Castling is separated and described before.

$bd->getfen($fen,$posini,$status) where $fen is the FEN string and $posini a hash reference used to initialize the game by :


$status is the status game as described before.

$bd->genfen($colmove,$status,$ep,$ply,$nmove) genfen is the inverse function of getfen. It returns the FEN string if we provides the classical chess data of the colors who had to play $colmove ('w' or 'b'), the status $status set by $bd->hasmoved($status), the column of the pawn if the taken "en passant" is possible $ep,the ply count $ply and at last, the game move count $nmove.

FUNCTIONS inside Chess::ChessKit::Trad ^

trad($outfile,$infile,$lang ,$lang2translate) translate an algebraic file or pgn given by $infile to $outfile where the source language is $lang and the output language is $lang2translate. They can take the following values: Czech|Danish|Dutch|English|Estonian|Finnish|French|German|Hungarian| Icelandic|Italian|Norwegian|Polish|Portuguese|Romanian|Spanish|Swedish

@array_of_moves=dscrip(mov=>$ref_array_of_moves , ini=>$ref_hash_position) Translate a descriptive notation with the following format:

n. Whitemove BlackMove

where n is the move number followed by a dot then by the moves.(Note: last move of course could be only a white move) The input is a reference to the array of the moves in decriptive notation, An array in long algebraic notation is returned. If a $ref_hash_position is given then the global variable $bd is set to those values. By default, it is again the initial chess game position.




Charles Minc, <>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



Copyright 2005 Charles Minc, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: