Example #1
0
/**
 * hot_fields()
 */
function hot_fields($board_array, $current_player)
{
    $ret = array();
    $hot_array = new_board();
    $movable_opponents = find_movable_pieces($board_array, !$current_player);
    foreach ($movable_opponents as $from_field) {
        $possible_moves = possible_move_list($board_array, !$current_player, $from_field);
        foreach ($possible_moves as $to_field) {
            list($row, $col) = field_to_rowcol($to_field);
            $hot_array[$row][$col] = 'not empty';
        }
    }
    for ($row = 0; $row < 8; $row++) {
        for ($col = 0; $col < 8; $col++) {
            if ($hot_array[$row][$col] == 'not empty') {
                $ret[] = rowcol_to_field($row, $col);
            }
        }
    }
    return $ret;
}
Example #2
0
/**
 * find_movable_pieces() - Creates  $clickable (Array of field names)
 * Checks the board for pieces that can be moved.
 * If all your pieces are boxed in or any move would result in your king to
 * get into check, an empty array is returned, indicating the end of the game.
 */
function find_movable_pieces($board_array, $current_player)
{
    $ret = array();
    $player_pieces = get_player_pieces($current_player);
    for ($row = 0; $row < 8; $row++) {
        for ($col = 0; $col < 8; $col++) {
            $piece = $board_array[$row][$col];
            if ($piece != '' && strpos($player_pieces, $piece) !== false) {
                $field = rowcol_to_field($row, $col);
                // Check, if piece can move at all
                $moves = possible_move_list($board_array, $current_player, $field);
                // First entry of the returned move list is
                // the FIELD of the currently checked piece:
                if (isset($moves[1])) {
                    $ret[] = $field;
                    // == $moves[0];
                }
            }
        }
    }
    return $ret;
}
Example #3
0
/**
 * get_pieces() - Get associative array of pieces orderd by field name
 */
function get_pieces($board)
{
    $ret = array();
    for ($row = 0; $row < 8; $row++) {
        for ($col = 0; $col < 8; $col++) {
            if ($board[$row][$col] != '') {
                $field = rowcol_to_field($row, $col);
                $ret[$field] = $board[$row][$col];
            }
        }
    }
    return $ret;
}
Example #4
0
function decode_field($code)
{
    $p = strpos(LOCATION_CODES, $code);
    $col = $p % 8;
    $row = ($p - $col) / 8;
    return rowcol_to_field($row, $col);
}