/**
* @file
* Routines for dealing with Plane objects that occur in the 'planes' array in the Qube object.
*
* Last Modified: Sun Aug 28 14:37:41 PDT 2016
* @author Kevin O'Gorman
*/
/*
* Copyright 2002 Santiago Canez <scanez@math.berkeley.edu>
* Copyright 2012,2013,2016 Kevin O'Gorman <kogorman@gmail.com>.
* Distributed under the GNU General Public License.
*
* This file is part of libqubist, the library of functions for playing
* 4x4x4 tic-tac-toe, also known by some other names outside the USA.
*
* Libqubist is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2.
*
* Libqubist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @file
* Routines for dealing with Plane objects that occur in the 'planes' array in the Qube object.
*
* Routines for dealing with Plane objects that occur in the 'planes' array in the Qube object.
* This defines the numbers that identify the 18 planes, and is used to populate and manage
* the cells of the planes array.
*/
#include <stdlib.h>
#include <stdio.h>
#include "board.h"
#include "plane.h"
#undef NDEBUG
#define NDEBUG
#include <assert.h>
/**
* A set of linear coefficients to describe a plane as k=0..3 and j=0..3
*/
struct qb_formula {
int kmul; /**< k multiplier */
int jmul; /**< j multiplier */
int offset; /**< constant */
};
/**
* Coefficients for 18 linear formulas to describe the 18 planes.
*/
struct qb_formula qb_plane_formulas[18] = {
{4, 1, 0}, /* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */
{4, 1, 16}, /* 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 */
{4, 1, 32}, /* 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 */
{4, 1, 48}, /* 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 */
{16, 4, 0}, /* 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 */
{16, 4, 1}, /* 2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 */
{16, 4, 2}, /* 3 7 11 15 19 23 27 31 35 39 43 47 51 55 59 63 */
{16, 4, 3}, /* 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 */
{16, 1, 0}, /* 1 2 3 4 17 18 19 20 33 34 35 36 49 50 51 52 */
{16, 1, 4}, /* 5 6 7 8 21 22 23 24 37 38 39 40 53 54 55 56 */
{16, 1, 8}, /* 9 10 11 12 25 26 27 28 41 42 43 44 57 58 59 60 */
{16, 1, 12}, /* 13 14 15 16 29 30 31 32 45 46 47 48 61 62 63 64 */
{20, 1, 0}, /* 1 2 3 4 21 22 23 24 41 42 43 44 61 62 63 64 */
{17, 4, 0}, /* 1 5 9 13 18 22 26 30 35 39 43 47 52 56 60 64 */
{12, 1, 12}, /* 13 14 15 16 25 26 27 28 37 38 39 40 49 50 51 52 */
{15, 4, 3}, /* 4 8 12 16 19 23 27 31 34 38 42 46 49 53 57 61 */
{16, 5, 0}, /* 1 6 11 16 17 22 27 32 33 38 43 48 49 54 59 64 */
{16, 3, 3} /* 4 7 10 13 20 23 26 29 36 39 42 45 52 55 58 61 */
};
#if 0 /* now obsolete, since the Qube does not contain a list of planes */
/**
* Initialize the planes array. Each of 18 Plane objects needs 16 entries, each pointing
* to a square in the plane being modeled by the Plane.
* First, three stacks of 4 planes each, each stack being along one of the 3 dimensions.
* Then, 6 planes formed by diagonal slices through the cube, each going through 2
* opposite edges (there are 6 pairs of such opposites).
* These are not variable once initialized.
*/
void
qb_initialize_planes(Qube *board)
{
int p, j, k;
Plane *pptr;
Square **iptr;
pptr = board->planes;
for (p = 0; p < 18; p++) {
iptr = pptr->squares;
for (j = 0; j < 4; j++) {
for (k = 0; k < 4; k++) {
iptr[k * 4 + j] = &board->squares[
qb_plane_formulas[p].jmul * j +
qb_plane_formulas[p].kmul * k +
qb_plane_formulas[p].offset
];
}
}
pptr++;
}
#ifndef NDEBUG
/* If debugging, output the array of planes (1-based) to allow visual verification */
for (p = 0; p < 18; p++) {
printf("%2d", p + 1);
for (j = 0; j < 16; j++) {
printf("%3d", 1 + get_square_num(board, board->planes[p].squares[j]));
}
printf("\n");
}
#endif
}
#endif
/* vim: set expandtab autoindent shiftround nosmartindent tabstop=8 softtabstop=2 shiftwidth=2: */