My Project
count_last_flip_plain.c File Reference

Functions

int last_flip (int pos, unsigned long long P)
 

Variables

static const unsigned char COUNT_FLIP [8][256]
 
static const unsigned long long mask_d [2][64]
 

Detailed Description

A function is provided to count the number of fipped disc of the last move.

The basic principle is to read into an array a precomputed result. Doing this is easy for a single line ; as we can use arrays of the form:

  • COUNT_FLIP[square where we play][8-bits disc pattern]. The problem is thus to convert any line of a 64-bits disc pattern into an 8-bits disc pattern. A fast way to do this is to select the right line, with a bit-mask, to gather the masked-bits into a continuous set by a simple multiplication and to right-shift the result to scale it into a number between 0 and 255. Once we get our 8-bits disc patterns, we directly get the number of flipped discs from the precomputed array, and add them from each flipping lines. For optimization purpose, the value returned is twice the number of flipped disc, to facilitate the computation of disc difference.
Date
1998 - 2017
Author
Richard Delorme
Toshihiko Okuhara
Version
4.4

Function Documentation

◆ last_flip()

int last_flip ( int pos,
unsigned long long P )

Count last flipped discs when playing on the last empty.

Parameters
posthe last empty square.
Pplayer's disc pattern.
Returns
flipped disc count.

Variable Documentation

◆ COUNT_FLIP

const unsigned char COUNT_FLIP[8][256]
static

precomputed count flip array

◆ mask_d

const unsigned long long mask_d[2][64]
static