// ******************************************************************* // (C) Copyright 2013 Leiden Institute of Advanced Computer Science // Universiteit Leiden // All Rights Reserved // ******************************************************************* // DouShouQi (core) // ******************************************************************* // FILE INFORMATION: // File: movement.h // Author: Jonathan K. Vis // Revision: 1.01a // Date: 2013/04/11 // ******************************************************************* // DESCRIPTION: // Defines the movement capabilities of all the pieces for all // locations of the board. // ******************************************************************* #if !defined(__movement_h__) #define __movement_h__ #include "types.h" static uint32_t const STEP_NORTH = 0; static uint32_t const STEP_EAST = 1; static uint32_t const STEP_SOUTH = 2; static uint32_t const STEP_WEST = 3; static uint32_t const LEAP_NORTH = 4; static uint32_t const LEAP_EAST = 5; static uint32_t const LEAP_SOUTH = 6; static uint32_t const LEAP_WEST = 7; static uint32_t const MOVEMENT[16][64] = { { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_RAT { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_RAT { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_CAT { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_CAT { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_WOLF { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_WOLF { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_DOG { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_DOG { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_PANTHER { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_PANTHER { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 75, 75, 15, 75, 75, 13, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 7, 30, 30, 15, 30, 30, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_TIGER { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 75, 75, 15, 75, 75, 13, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 7, 30, 30, 15, 30, 30, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_TIGER { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 75, 75, 15, 75, 75, 13, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 7, 30, 30, 15, 30, 30, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_LION { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 75, 75, 15, 75, 75, 13, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 37, 0, 0, 165, 0, 0, 133, 7, 30, 30, 15, 30, 30, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 }, // BLACK_LION { 6, 14, 14, 14, 14, 14, 12, 7, 15, 15, 15, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 11, 15, 15, 13, 3, 11, 9, 0, 3, 11, 9, 0 }, // WHITE_ELEPHANT { 6, 14, 12, 0, 6, 14, 12, 7, 15, 15, 14, 15, 15, 13, 7, 11, 11, 15, 11, 11, 13, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 5, 0, 0, 5, 0, 0, 5, 7, 14, 14, 15, 14, 14, 13, 7, 15, 15, 15, 15, 15, 13, 3, 11, 11, 11, 11, 11, 9, 0 } // BLACK_ELEPHANT }; // MOVEMENT static uint32_t const MOVEMENT_MASK[8] = { 1, // STEP_NORTH 2, // STEP_EAST 4, // STEP_SOUTH 8, // STEP_WEST 16, // LEAP_NORTH 32, // LEAP_EAST 64, // LEAP_SOUTH 128 // LEAP_WEST }; // MOVEMENT_MASK static int const MOVEMENT_OFFSET[8] = { -7, // STEP_NORTH 1, // STEP_EAST 7, // STEP_SOUTH -1, // STEP_WEST -28, // LEAP_NORTH 3, // LEAP_EAST 28, // LEAP_SOUTH -3 // LEAP_WEST }; // MOVEMENT_OFFSET // this function is branchless // the parameter to is updated in all cases, but guaranteed to be // within the boundaries of the board static inline bool can_move(uint32_t const piece, uint32_t const from, uint32_t const direction, uint32_t &to) { to = (from + MOVEMENT_OFFSET[direction]) & 63; return (MOVEMENT[piece][from] & MOVEMENT_MASK[direction]) > 0; } // can_move #endif