/**
* Find best position for next step of computer player, and return the
* step score.
*/
static SINT16 FCMainFindBestPosition(SINT8 * s8SelPosX, SINT8 * s8SelPosY,
UINT8 u8ComputerPlayer,
UINT8 u8PeoplePlayer)
{
int i; /* for loop to count 5 power of u8LimitNum */
UINT8 u8PosX, u8PosY; /* for loop hole chess board */
UINT8 u8LimitNum = 0; /* for loop from five chess lint to two */
/* chess lint */
SINT16 s16Temp = 1; /* power value of 5 power of u8LimitNum */
SINT32 s32NumPosSel = 0; /* for count power of every position which */
/* is FC_NO_PALYER */
SINT32 s32MaxPosSel = 0; /* record max power of all position */
SINT32 s32Temp = 0; /* power value of */
/*FCMainFindConnectLinesByPoint() */
SINT16 s16StepScore = 0; /* return of step score */
/* from five chess lint to two chess lint */
for (u8LimitNum = 5; u8LimitNum >= 2; u8LimitNum--) {
/* loop hole chess board */
for (u8PosX = 0; u8PosX < FC_BOARD_WIDTH; u8PosX++) {
for (u8PosY = 0; u8PosY < FC_BOARD_HEIGHT; u8PosY++) {
/* only count position which is FC_NO_PALYER */
if (nFiveChessBoard[u8PosX][u8PosY] == FC_NO_PALYER) {
/* count 5 power of u8LimitNum */
s16Temp = 1;
for (i = 0; i < 5; i++) {
s16Temp = s16Temp * u8LimitNum;
}
/* first count computer player's power value */
s32Temp =
FCMainFindConnectLinesByPoint(u8PosX, u8PosY,
(UINT8)
nComputerPlayer,
u8LimitNum);
/* count power of the position */
s32NumPosSel =
(s32Temp * s16Temp + 1) * 10 +
FCMainPositionPower(u8PosX, u8PosY);
if (s32NumPosSel > s32MaxPosSel) {
s32MaxPosSel = s32NumPosSel;
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
} else if (s32NumPosSel == s32MaxPosSel) {
if ((FCPalRand() & 0x01) == 1) {
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
}
}
/* the count people player's power value */
s32Temp =
FCMainFindConnectLinesByPoint(u8PosX, u8PosY,
(UINT8)
nPeoplePlayer,
u8LimitNum);
s32NumPosSel =
(s32Temp * s16Temp) * 10 +
FCMainPositionPower(u8PosX, u8PosY);
if (s32NumPosSel == s32MaxPosSel) {
if ((FCPalRand() & 0x01) == 1) {
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
}
} else if (s32NumPosSel > s32MaxPosSel) {
s32MaxPosSel = s32NumPosSel;
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
}
} /* if */
} /* for */
} /* for */
} /* for */
/**
* Find best position for next step of computer player, and return the step score.
*/
static SINT16 FCMainFindBestPosition(SINT8 * s8SelPosX, SINT8 * s8SelPosY, UINT8 u8ComputerPlayer, UINT8 u8PeoplePlayer)
{
int i; /* for loop to count 5 power of u8LimitNum */
UINT8 u8PosX, u8PosY; /* for loop hole chess board */
UINT8 u8LimitNum = 0; /* for loop from five chess lint to two chess lint */
SINT16 s16Temp = 1; /* power value of 5 power of u8LimitNum */
SINT32 s32NumPosSel = 0; /* for count power of every position which is FC_NO_PALYER */
SINT32 s32MaxPosSel = 0; /* record max power of all position */
SINT32 s32Temp = 0; /* power value of FCMainFindConnectLinesByPoint() */
SINT16 s16StepScore = 0; /* return of step score */
/* from five chess lint to two chess lint */
for (u8LimitNum = 5; u8LimitNum >= 2; u8LimitNum--) {
/* loop hole chess board */
for (u8PosX = 0; u8PosX < FC_BOARD_WIDTH; u8PosX++) {
for (u8PosY = 0; u8PosY < FC_BOARD_HEIGHT; u8PosY++) {
/* only count position which is FC_NO_PALYER */
if (nFiveChessBoard[u8PosX][u8PosY] == FC_NO_PALYER) {
/* count 5 power of u8LimitNum */
s16Temp = 1;
for (i = 0; i < 5; i++) {
s16Temp = s16Temp * u8LimitNum;
}
/* first count computer player's power value */
s32Temp = FCMainFindConnectLinesByPoint(u8PosX, u8PosY, (UINT8) nComputerPlayer, u8LimitNum);
/* count power of the position */
s32NumPosSel = (s32Temp * s16Temp + 1) * 10 + FCMainPositionPower(u8PosX, u8PosY);
if (s32NumPosSel > s32MaxPosSel) {
s32MaxPosSel = s32NumPosSel;
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
} else if (s32NumPosSel == s32MaxPosSel) {
if ((FCPalRand() & 0x01) == 1) {
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
}
}
/* the count people player's power value */
s32Temp = FCMainFindConnectLinesByPoint(u8PosX, u8PosY, (UINT8) nPeoplePlayer, u8LimitNum);
s32NumPosSel = (s32Temp * s16Temp) * 10 + FCMainPositionPower(u8PosX, u8PosY);
if (s32NumPosSel == s32MaxPosSel) {
if ((FCPalRand() & 0x01) == 1) {
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
}
} else if (s32NumPosSel > s32MaxPosSel) {
s32MaxPosSel = s32NumPosSel;
*s8SelPosX = u8PosX;
*s8SelPosY = u8PosY;
}
} /* if */
} /* for */
} /* for */
} /* for */