Chess-Plisco

 view release on metacpan or  search on metacpan

lib/Chess/Plisco.pm  view on Meta::CPAN

#! /bin/false

# Copyright (C) 2021-2026 Guido Flohr <guido.flohr@cantanea.com>,
# all rights reserved.

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What the Fuck You Want
# to Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.

# Portions of this code have been ported from C code that has the following
# copyright notice:

# Copyright (C) 2007 Pradyumna Kannan.
#
# This code is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from
# the use of this code. Permission is granted to anyone to use this
# code for any purpose, including commercial applications, and to alter
# it and redistribute it freely, subject to the following restrictions:
# 
# 1. The origin of this code must not be misrepresented; you must not
# claim that you wrote the original code. If you use this code in a
# product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original code.
# 
# 3. This notice may not be removed or altered from any source distribution.

# Make Dist::Zilla happy.
# ABSTRACT: Representation of a chess position with move generator, legality checker etc.

# Welcome to the world of spaghetti code!  It is deliberately ugly because
# trying to avoid function/method call overhead is one of the major goals.
# In the future it may make sense to try to make the code more readable by
# more extensive use of Chess::Plisco::Macro.

package Chess::Plisco;
$Chess::Plisco::VERSION = 'v1.0.3';
use strict;
use integer;

use Locale::TextDomain qw('Chess-Plisco');
use Scalar::Util qw(reftype);
use Config;

# Macros from Chess::Plisco::Macro are already expanded here!

use base qw(Exporter);

# Colours.
use constant CP_WHITE => 0;
use constant CP_BLACK => 1;

# Piece constants.
use constant CP_NO_PIECE => 0;
use constant CP_PAWN => 1;
use constant CP_KNIGHT => 2;
use constant CP_BISHOP => 3;
use constant CP_ROOK => 4;
use constant CP_QUEEN => 5;
use constant CP_KING => 6;
use constant CP_PAWN_VALUE => 100;
use constant CP_KNIGHT_VALUE => 320;
use constant CP_BISHOP_VALUE => 330;
use constant CP_ROOK_VALUE => 500;
use constant CP_QUEEN_VALUE => 900;

# Accessor indices.  The layout is selected in such a way that piece types
# can be used directly as indices in order to get the corresponding bitboard,
# and getting the pieces for the side to move and the side not to move can
# be simplified by just adding the colour or the negated colour to the index
# of the white pieces.  This must not change in future versions!
use constant CP_POS_HALFMOVES => 0;
use constant CP_POS_PAWNS => CP_PAWN;
use constant CP_POS_KNIGHTS => CP_KNIGHT;
use constant CP_POS_BISHOPS => CP_BISHOP;
use constant CP_POS_ROOKS => CP_ROOK;
use constant CP_POS_QUEENS => CP_QUEEN;
use constant CP_POS_KINGS => CP_KING;
use constant CP_POS_WHITE_PIECES => 7;
use constant CP_POS_BLACK_PIECES => 8;
use constant CP_POS_LAST_MOVE => 9;
use constant CP_POS_MATERIAL => 10;
use constant CP_POS_HALFMOVE_CLOCK => 11;
use constant CP_POS_TURN => 12;
use constant CP_POS_TO_MOVE => 12;
use constant CP_POS_EN_PASSANT_SHIFT => 13;
# 5 reserved slots.
use constant CP_POS_USR1 => 14;
use constant CP_POS_USR2 => 15;
use constant CP_POS_USR3 => 16;
use constant CP_POS_USR4 => 17;
use constant CP_POS_USR5 => 18;
use constant CP_POS_USR6 => 19;
use constant CP_POS_CASTLING_RIGHTS => 20;

# Board masks and shifts.
# Squares.
use constant CP_A1 => 0;
use constant CP_B1 => 1;
use constant CP_C1 => 2;
use constant CP_D1 => 3;
use constant CP_E1 => 4;
use constant CP_F1 => 5;
use constant CP_G1 => 6;
use constant CP_H1 => 7;



( run in 0.481 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )