|
Post by Kristal Rose Phoenix McKinstry on Nov 4, 2005 2:01:46 GMT -5
<?php #fd ########################################################################################## ######################### SMC CS85 CHESS PROGRAM ######################################### ########################################################################################## if ($ulShowVersions) print(' // test for declared check #### oTest.rpq ###########################################################################<br /> #### 2005.12.12 20:00 - km castling tests. ###############<br /> #### 2005.12.12 18:00 - km tests complete except obstructions and castling ###############<br /> #### 2005.11.11 18:00 - km calling oTestMove->fTestMove directly from ###############<br /> #### chess.php with oCFV arg. ###############<br /> #### 2005.11.07 19:05 - km Modified optional constructor args. ###############<br />'); #### 2005.11.05 09:15 - km RESTRUCTURED VARS AND CONSTRUCTOR. ###############<br />'); #### 2005.11.03 18:00 - km fTestMove returns TRUE. ###############<br />'); ########################################################################################## ########################################################################################## #### Status: Multiple simultaneous file versions each Locked by member. ############### ########################################################################################## ########################################################################################## #### Description: #################################### #### #################################### #### Look at fGetNewBoard for a sample protocol #################################### #### b & w (black and white) have been changed to l & d (light & dark) ############## #### so that one can parse-search for 'b' and find a Bishop, not just ############## #### any black piece. ############## #### Pieces are now numbered to uniquely identify pieces for better game ############## #### processing and better display. Eg. 'dn02' (2nd dark knight). ############## #### Keeping in mind that pieces can be swapped for other piece, ############## #### naming protcol is as follows: ############## #### prefix: 'l' or 'd' (light or dark) ############## #### 'r'(rook) 01,02 + additional 03-15 ############## #### 'n'(knight) 01,02 + additional 03-15 ############## #### 'b'(bishop) 01,02 + additional 03-15 ############## #### 'q'(queen) 01 + additional 02-15 * #02 probably never used. ############## #### 'k'(king) 01 *# added for consistency, can't trade in king ############## #### 'p'(pawn) 01-08 + additional 08-15 ############## ########################################################################################## #### ############# #### BOARD STRUCTURE (STORED in qtBoards): ############# #### {{'dr01', 'dn01', 'db01', 'dq01', 'dk01', 'db02', 'dn02', 'dr02'}, ############# #### {'dp01', 'dp02', 'dp03', 'dp04', 'dp05', 'dp06', 'dp07', 'dp08'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'lp01', 'lp02', 'lp03', 'lp04', 'lp05', 'lp06', 'lp07', 'lp08'}, ############# #### {'lr01', 'ln01', 'lb01', 'lq01', 'lk01', 'lb02', 'ln02', 'lr02'}} ############# #### ############# #### For instance: ############# #### ############# #### {{'ss', 'dn01', 'db01', 'dq01', 'dk01', 'db02', 'dn02', 'dr02'}, ############# #### {'ss', 'dp02', 'dp03', 'dp04', 'dp05', 'dp06', 'dp07', 'dp08'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'dr01', 'ss'}, ############# #### {'dp01', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ln02', 'lp07', 'lb02'}, ############# #### {'lp01', 'lp02', 'lp03', 'lp04', 'lp05', 'lp06', 'ss', 'lp08'}, ############# #### {'lr01', 'ln01', 'lb01', 'lq01', 'ss', 'lr02', 'lk01', 'ss'}} ############# #### ############# #### ! A history of boards will be stored for each game. ############# #### ############# #### Note that board arrays in qtBoards are stored as serialized arrays. ############# #### oTest will be handed an array, but if you make sql call to qtboards ############# #### you will have to call unserialize(thatBoardArray). ############# #### ############# #### ############# #### ############# ########################################################################################## #### Programmers: KS, DT, and SS. ########################################################################################## ########################################################################################## #### Agenda: ############################################################################# #### From != ss, From == Their piece, To != From. ############# #### ############# ########################################################################################## ########################################################################################## ########################################################################################## /* possible methods ......fTestMove (laMove) ........fIdentifyPathType ..........returns: laPathType[clockDirection(1-12), steps] ........fBuildPathArray ........fPathIsObstructed ........fCellInCheck ........fCellIsObstructed ........fPathAppropriate (laPathType, lsPiece, liPlayer, liPlayerTurn)
ESTIMATED COMPLETION TIME: 0:00 Construct testing environment (should be unneccessary, just use existing game app and run a script in sTestTemp). 6:00 Additional testing functions (calls to explicit methods in sTestTemp). 1:00 test for Player two using flipped board and flipped MoveArray. 2:00 Create basic control structure (which test, ie fTestBishop) 4:00 Create basic environment (ie new test game and sequence of test boards) 4:00 Write sub-function utilities ie fIsCellOccupied 12:00 Write simple tests ie fTestBishop 2:00 fTestKing (easiest) 2:00 fTestRook (next easiest) 2:00 fTestBishop 1:00 fTestKnight (doesn't require obstructed-path test) 3:00 fTestPawn (requires testing game board history) 2:00 fTestQueen (use ftestRook and fTestBishop methods) 1:00 Write en passant tests for pawn 3:00 Write castle moves
33:00 TOTAL HOURS */
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class oTestMove { var $voServer; var $vaMove; var $voGame; var $voTestGame; var $vsTestGameId; var $voBoard; var $vaBoard; var $vlFakeGame; // Logical value. If Temporary game (TRUE), game can be deleted // from database by a method here calling oGame->fDestroyGame($lsGameId). var $voCFV; var $vsColor; # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ function oTestMove(&$loServer, $loCFV, $laMoveToTest='zilch', $loGame='zilch', $loBoard='zilch', $laBoard='zilch', $lsSpecial='zilch', $lsPlayerColor='zilch'){ $this->voServer = $loServer; $this->voCFV = $loCFV; if ($laMoveToTest =='zilch') $laMoveToTest = array(0,0,0,0); $this->vaMove = $laMoveToTest; // If optional arguments arent supplied: //Use $loCFV->fGetVal('vhPlayer') to get player id. //Use $loCFV->fGetMove to get move to test. //Use $loCFV->fGetVal('vsMove') to get special Moves and declarations. //$lsPlayerColor is 'l' or 'd'. $T=FALSE;
if ($loGame !='zilch') $this->vlFakeGame = FALSE; else{ //$loS = new oServer();//unnecc. $loId = new oId($loS); $lsGameId = $loId->fGetUniqueId('gameId'); $this->vlFakeGame = TRUE; $loGame = new oGame($loS, $lsGameId); }//end-else $this->voGame = $loGame;
if ($laBoard =='zilch'){ ####// Have to make sure Games automatically have boards first though. //$this->vaBoard = $this->voGame->fGetCurrentBoard($loServer); // shouldn't have worked $this->vaBoard = $this->voGame->fGetCurrentBoard(); }//end-if if ($T) exhibit_array($this->vaBoard); $this->voBoard = new oBoard($this->vaBoard);
}//end-meth constructor # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //function fTestMove($laMoveToTest='zilch', $loGame='zilch', $loBoard='zilch', $lsSpecial='zilch', $laBoard='zilch', $llDeclaredCheck='zilch'){ function fTestMove(){ // Create vector path/sequence (in fake game with boards) for testing obstructions (except final jump) $T = FALSE; $laMove = $this->voCFV->fGetMove(); //var_dump($laMove);
$liTurnNum = $this->voGame->fGetCurrentTurnNum(); //echocall("Turn num was $liTurnNum ", $T); if ($liTurnNum & 1) $this->vsColor = 'd'; // odd turn num else $this->vsColor = 'l'; echocall("fTM: Color was $this->vsColor", $T);
$lsPiece = $this->voBoard->fGetPiece($laMove[1], $laMove[0]); $lsDestPiece = $this->voBoard->fGetPiece($laMove[3], $laMove[2]);
$lsColor = substr($lsPiece, 0, 1); $lsDestColor = substr($lsDestPiece, 0, 1); $lsPieceType = substr($lsPiece, 1, 1); echocall("piece was a $lsColor $lsPieceType", $T);
/* $llDeclaredCheck = FALSE; if ($liTurnNum-2==(integer)$this->voGame->fGetWinner()) $llDeclaredCheck = TRUE; if (!($llDeclaredCheck===TRUE) AND (substr($lsDestPiece, 1, 1)=='k')) return FALSE; // attacked king without declaring check */ //worked if (($liTurnNum-2!=(integer)$this->voGame->fGetWinner()) AND (substr($lsDestPiece, 1, 1)=='k')) return FALSE; // attacked king without declaring check
if ($lsColor!=$this->vsColor) return FALSE; // Origin piece was not their's. if ($lsDestColor==$this->vsColor) return FALSE; // Attacked their own piece. if (($lsDestColor!=$this->vsColor) AND ($lsDestColor!='s')) $llIsAttack = TRUE; // Move attacks partner. else $llIsAttack = FALSE; // Not an attack move. if ($laMove[0]==$laMove[2] AND $laMove[1]==$laMove[3]) return FALSE; // Didn't actually move.
$liHorz = $laMove[3] - $laMove[1]; // for light, 11 is upper left, 88 is lower right. '+' = rightward. $liVert = $laMove[0] - $laMove[2]; // for light '+' is upward (cool for pawns) echocall("Horz/Vert was $liHorz/$liVert", $T);
$lsMove = (string)$this->voCFV->fGetVal('vsMove'); echocall("Selected was $lsMove", $T); // 0.Nothing selected 1.Castle - short, 2.Castle - long, 3.Declare check, 4.Declare check-mate switch ($lsMove){ // Some special moves overwrite pieces. case '1': $lsPieceType='1'; // castle - short break; case '2': $lsPieceType='2'; // castle - long break; case '5': $lsPieceType='5'; // en passant break; default: break; }//end-switch
echocall("before piece switch piece was $lsPieceType", $T);
switch ($lsPieceType){ case 's': return FALSE; // moved a space. break; case 'p': // !! need en passant, attack, & better first/subsequent turn tests. /*if ((not good direction) OR (+1 not first turn) OR (attack, diag, and(but) >1) OR (attack, not diag) OR (not attack, horz>0)) return FALSE;*/ if ( ( (($liVert<1) AND ($lsColor=='l')) OR (($liVert>=0) AND ($lsColor=='d')) // (not good direction) )
OR ((abs($liVert)>1) AND ((($laMove[0]!=2) AND ($lsColor=='d')) OR (($laMove[0]!=7) AND ($lsColor=='l'))) ) // (+1 not first turn)
OR (($llIsAttack == TRUE) AND (abs($liHorz)==abs($liVert)) AND (abs($liHorz)+abs($liVert)!=2)) // (attack, diag, and(but) >1)
OR (($llIsAttack == TRUE) AND (abs($liHorz)!=abs($liVert))) // (attack, not diag)
OR (($llIsAttack == FALSE) AND (abs($liHorz>0))) // (not attack, horz>0) ) return FALSE; break; case 'r': if ($liHorz!=0 AND $liVert!=0) return FALSE; // Rook moved both vert and horz break; case 'n': if (abs($liHorz)+abs($liVert)!=3 OR abs($liHorz)==3 OR abs($liVert)==3) return FALSE; break; case 'b': if (abs($liHorz)!=abs($liVert)) return FALSE; // Bishops move was not pure diagonal. return TRUE; // break; case 'q': if ((abs($liHorz)!=abs($liVert)) && (($liHorz!=0) && ($liVert!=0)) ) return FALSE; // not a bishop move or rook move. break; case 'k': if (abs($liHorz)>1 OR abs($liVert)>1) return FALSE; break;
case '1': // castle - short // no historical test yet! if ((substr($this->voBoard->fGetPiece(5, $laMove[0]), 1, 1)!='k') OR (substr($this->voBoard->fGetPiece(8, $laMove[0]), 1, 1)!='r') OR (substr($this->voBoard->fGetPiece(6, $laMove[0]), 1, 1)!='s') OR (substr($this->voBoard->fGetPiece(7, $laMove[0]), 1, 1)!='s') ) return FALSE; break; case '2': // castle - long if ((substr($this->voBoard->fGetPiece(5, $laMove[0]), 1, 1)!='k') OR (substr($this->voBoard->fGetPiece(1, $laMove[0]), 1, 1)!='r') OR (substr($this->voBoard->fGetPiece(2, $laMove[0]), 1, 1)!='s') OR (substr($this->voBoard->fGetPiece(3, $laMove[0]), 1, 1)!='s') OR (substr($this->voBoard->fGetPiece(4, $laMove[0]), 1, 1)!='s') ) return FALSE; break; case '5': // en passant selected // a) get color, get col // b) own pawn moved to 5th row, enemy behind them, from adj 4th // c) enemy pawn was at 2nd row last turn { // begin-case echocall('doing case 5', $T);
if (substr($lsPiece, 0, 2)=='lp') { echocall('was a lp', $T);
$lsBehind = $this->voBoard->fGetPiece($laMove[3], 4); echocall("Behind was $lsBehind", $T);
if ((substr($lsBehind, 0, 2)=='dp') AND ($laMove[2]==3)) { echocall ('en passant light called', $T); $laPriorBoard = $this->voGame->fGetCurrentBoard($liTurnNum-2); $loPriorBoard = new oBoard($laPriorBoard); $lsPriorPiece = $loPriorBoard->fGetPiece($laMove[3], 2); if ($lsBehind==$lsPriorPiece) return TRUE; else return FALSE; }//end-if } // end-if color
if (substr($lsPiece, 0, 2)=='dp') { echocall('was a dp', $T);
$lsBehind = $this->voBoard->fGetPiece($laMove[3], 5); echocall("Behind was $lsBehind", $T);
if ((substr($lsBehind, 0, 2)=='lp') AND ($laMove[2]==6)) { echocall ('en passant dark called', $T); $laPriorBoard = $this->voGame->fGetCurrentBoard($liTurnNum-2); $loPriorBoard = new oBoard($laPriorBoard); $lsPriorPiece = $loPriorBoard->fGetPiece($laMove[3], 7); if ($lsBehind==$lsPriorPiece) return TRUE; else return FALSE; }//end-if } // end-if color
else return FALSE; } // end-case break;
default: return TRUE; // drastic error, not a piece. break; }//end-switch
return TRUE; }//end-meth # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ }//end-class #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
Post by Kristal Rose Phoenix McKinstry on Nov 14, 2006 23:32:35 GMT -5
// ok, I never did post the final version. Here it is:
<?php #fd ########################################################################################## ######################### SMC CS85 CHESS PROGRAM ######################################### ########################################################################################## if ($ulShowVersions) print(' // test for declared check #### oTest.rpq ###########################################################################<br /> #### 2005.12.12 20:00 - km castling tests. ###############<br /> #### 2005.12.12 18:00 - km tests complete except obstructions and castling ###############<br /> #### 2005.11.11 18:00 - km calling oTestMove->fTestMove directly from ###############<br /> #### chess.php with oCFV arg. ###############<br /> #### 2005.11.07 19:05 - km Modified optional constructor args. ###############<br />'); #### 2005.11.05 09:15 - km RESTRUCTURED VARS AND CONSTRUCTOR. ###############<br />'); #### 2005.11.03 18:00 - km fTestMove returns TRUE. ###############<br />'); ########################################################################################## ########################################################################################## #### Status: Multiple simultaneous file versions each Locked by member. ############### ########################################################################################## ########################################################################################## #### Description: #################################### #### #################################### #### Look at fGetNewBoard for a sample protocol #################################### #### b & w (black and white) have been changed to l & d (light & dark) ############## #### so that one can parse-search for 'b' and find a Bishop, not just ############## #### any black piece. ############## #### Pieces are now numbered to uniquely identify pieces for better game ############## #### processing and better display. Eg. 'dn02' (2nd dark knight). ############## #### Keeping in mind that pieces can be swapped for other piece, ############## #### naming protcol is as follows: ############## #### prefix: 'l' or 'd' (light or dark) ############## #### 'r'(rook) 01,02 + additional 03-15 ############## #### 'n'(knight) 01,02 + additional 03-15 ############## #### 'b'(bishop) 01,02 + additional 03-15 ############## #### 'q'(queen) 01 + additional 02-15 * #02 probably never used. ############## #### 'k'(king) 01 *# added for consistency, can't trade in king ############## #### 'p'(pawn) 01-08 + additional 08-15 ############## ########################################################################################## #### ############# #### BOARD STRUCTURE (STORED in qtBoards): ############# #### {{'dr01', 'dn01', 'db01', 'dq01', 'dk01', 'db02', 'dn02', 'dr02'}, ############# #### {'dp01', 'dp02', 'dp03', 'dp04', 'dp05', 'dp06', 'dp07', 'dp08'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'lp01', 'lp02', 'lp03', 'lp04', 'lp05', 'lp06', 'lp07', 'lp08'}, ############# #### {'lr01', 'ln01', 'lb01', 'lq01', 'lk01', 'lb02', 'ln02', 'lr02'}} ############# #### ############# #### For instance: ############# #### ############# #### {{'ss', 'dn01', 'db01', 'dq01', 'dk01', 'db02', 'dn02', 'dr02'}, ############# #### {'ss', 'dp02', 'dp03', 'dp04', 'dp05', 'dp06', 'dp07', 'dp08'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'dr01', 'ss'}, ############# #### {'dp01', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss', 'ss'}, ############# #### {'ss', 'ss', 'ss', 'ss', 'ss', 'ln02', 'lp07', 'lb02'}, ############# #### {'lp01', 'lp02', 'lp03', 'lp04', 'lp05', 'lp06', 'ss', 'lp08'}, ############# #### {'lr01', 'ln01', 'lb01', 'lq01', 'ss', 'lr02', 'lk01', 'ss'}} ############# #### ############# #### ! A history of boards will be stored for each game. ############# #### ############# #### Note that board arrays in qtBoards are stored as serialized arrays. ############# #### oTest will be handed an array, but if you make sql call to qtboards ############# #### you will have to call unserialize(thatBoardArray). ############# #### ############# #### ############# #### ############# ########################################################################################## #### Programmers: KS, DT, and SS. ########################################################################################## ########################################################################################## #### Agenda: ############################################################################# #### From != ss, From == Their piece, To != From. ############# #### ############# ########################################################################################## ########################################################################################## ########################################################################################## /* possible methods ......fTestMove (laMove) ........fIdentifyPathType ..........returns: laPathType[clockDirection(1-12), steps] ........fBuildPathArray ........fPathIsObstructed ........fCellInCheck ........fCellIsObstructed ........fPathAppropriate (laPathType, lsPiece, liPlayer, liPlayerTurn)
ESTIMATED COMPLETION TIME: 0:00 Construct testing environment (should be unneccessary, just use existing game app and run a script in sTestTemp). 6:00 Additional testing functions (calls to explicit methods in sTestTemp). 1:00 test for Player two using flipped board and flipped MoveArray. 2:00 Create basic control structure (which test, ie fTestBishop) 4:00 Create basic environment (ie new test game and sequence of test boards) 4:00 Write sub-function utilities ie fIsCellOccupied 12:00 Write simple tests ie fTestBishop 2:00 fTestKing (easiest) 2:00 fTestRook (next easiest) 2:00 fTestBishop 1:00 fTestKnight (doesn't require obstructed-path test) 3:00 fTestPawn (requires testing game board history) 2:00 fTestQueen (use ftestRook and fTestBishop methods) 1:00 Write en passant tests for pawn 3:00 Write castle moves
33:00 TOTAL HOURS */
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class oTestMove { var $voServer; var $vaMove; var $voGame; var $voTestGame; var $vsTestGameId; var $voBoard; var $vaBoard; var $vlFakeGame; // Logical value. If Temporary game (TRUE), game can be deleted // from database by a method here calling oGame->fDestroyGame($lsGameId). var $voCFV; var $vsColor; # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ function oTestMove(&$loServer, $loCFV, $laMoveToTest='zilch', $loGame='zilch', $loBoard='zilch', $laBoard='zilch', $lsSpecial='zilch', $lsPlayerColor='zilch'){ $this->voServer = $loServer; $this->voCFV = $loCFV; if ($laMoveToTest =='zilch') $laMoveToTest = array(0,0,0,0); $this->vaMove = $laMoveToTest; // If optional arguments arent supplied: //Use $loCFV->fGetVal('vhPlayer') to get player id. //Use $loCFV->fGetMove to get move to test. //Use $loCFV->fGetVal('vsMove') to get special Moves and declarations. //$lsPlayerColor is 'l' or 'd'. $T=FALSE;
if ($loGame !='zilch') $this->vlFakeGame = FALSE; else{ //$loS = new oServer();//unnecc. $loId = new oId($loS); $lsGameId = $loId->fGetUniqueId('gameId'); $this->vlFakeGame = TRUE; $loGame = new oGame($loS, $lsGameId); }//end-else $this->voGame = $loGame;
if ($laBoard =='zilch'){ ####// Have to make sure Games automatically have boards first though. //$this->vaBoard = $this->voGame->fGetCurrentBoard($loServer); // shouldn't have worked $this->vaBoard = $this->voGame->fGetCurrentBoard(); }//end-if if ($T) exhibit_array($this->vaBoard); $this->voBoard = new oBoard($this->vaBoard);
}//end-meth constructor # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //function fTestMove($laMoveToTest='zilch', $loGame='zilch', $loBoard='zilch', $lsSpecial='zilch', $laBoard='zilch', $llDeclaredCheck='zilch'){ function fTestMove(){ // Create vector path/sequence (in fake game with boards) for testing obstructions (except final jump) $T = FALSE; $laMove = $this->voCFV->fGetMove(); //var_dump($laMove);
$liTurnNum = $this->voGame->fGetCurrentTurnNum(); //echocall("Turn num was $liTurnNum ", $T); if ($liTurnNum & 1) $this->vsColor = 'd'; // odd turn num else $this->vsColor = 'l'; echocall("fTM: Color was $this->vsColor", $T);
$lsPiece = $this->voBoard->fGetPiece($laMove[1], $laMove[0]); $lsDestPiece = $this->voBoard->fGetPiece($laMove[3], $laMove[2]);
$lsColor = substr($lsPiece, 0, 1); $lsDestColor = substr($lsDestPiece, 0, 1); $lsPieceType = substr($lsPiece, 1, 1); echocall("piece was a $lsColor $lsPieceType", $T);
/* $llDeclaredCheck = FALSE; if ($liTurnNum-2==(integer)$this->voGame->fGetWinner()) $llDeclaredCheck = TRUE; if (!($llDeclaredCheck===TRUE) AND (substr($lsDestPiece, 1, 1)=='k')) return FALSE; // attacked king without declaring check */ //worked if (($liTurnNum-2!=(integer)$this->voGame->fGetWinner()) AND (substr($lsDestPiece, 1, 1)=='k')) return FALSE; // attacked king without declaring check
if ($lsColor!=$this->vsColor) return FALSE; // Origin piece was not their's. if ($lsDestColor==$this->vsColor) return FALSE; // Attacked their own piece. if (($lsDestColor!=$this->vsColor) AND ($lsDestColor!='s')) $llIsAttack = TRUE; // Move attacks partner. else $llIsAttack = FALSE; // Not an attack move. if ($laMove[0]==$laMove[2] AND $laMove[1]==$laMove[3]) return FALSE; // Didn't actually move.
$liHorz = $laMove[3] - $laMove[1]; // for light, 11 is upper left, 88 is lower right. '+' = rightward. $liVert = $laMove[0] - $laMove[2]; // for light '+' is upward (cool for pawns) echocall("Horz/Vert was $liHorz/$liVert", $T);
$lsMove = (string)$this->voCFV->fGetVal('vsMove'); echocall("Selected was $lsMove", $T); // 0.Nothing selected 1.Castle - short, 2.Castle - long, 3.Declare check, 4.Declare check-mate switch ($lsMove){ // Some special moves overwrite pieces. case '1': $lsPieceType='1'; // castle - short break; case '2': $lsPieceType='2'; // castle - long break; case '5': $lsPieceType='5'; // en passant break; default: break; }//end-switch
echocall("before piece switch piece was $lsPieceType", $T);
switch ($lsPieceType){ case 's': return FALSE; // moved a space. break; case 'p': // !! need en passant, attack, & better first/subsequent turn tests. /*if ((not good direction) OR (+1 not first turn) OR (attack, diag, and(but) >1) OR (attack, not diag) OR (not attack, horz>0)) return FALSE;*/ if ( ( (($liVert<1) AND ($lsColor=='l')) OR (($liVert>=0) AND ($lsColor=='d')) // (not good direction) )
OR ((abs($liVert)>1) AND ((($laMove[0]!=2) AND ($lsColor=='d')) OR (($laMove[0]!=7) AND ($lsColor=='l'))) ) // (+1 not first turn)
OR (($llIsAttack == TRUE) AND (abs($liHorz)==abs($liVert)) AND (abs($liHorz)+abs($liVert)!=2)) // (attack, diag, and(but) >1)
OR (($llIsAttack == TRUE) AND (abs($liHorz)!=abs($liVert))) // (attack, not diag)
OR (($llIsAttack == FALSE) AND (abs($liHorz>0))) // (not attack, horz>0) ) return FALSE; break; case 'r': if ($liHorz!=0 AND $liVert!=0) return FALSE; // Rook moved both vert and horz break; case 'n': if (abs($liHorz)+abs($liVert)!=3 OR abs($liHorz)==3 OR abs($liVert)==3) return FALSE; break; case 'b': if (abs($liHorz)!=abs($liVert)) return FALSE; // Bishops move was not pure diagonal. return TRUE; // break; case 'q': if ((abs($liHorz)!=abs($liVert)) && (($liHorz!=0) && ($liVert!=0)) ) return FALSE; // not a bishop move or rook move. break; case 'k': if (abs($liHorz)>1 OR abs($liVert)>1) return FALSE; break;
case '1': // castle - short // no historical test yet! if ((substr($this->voBoard->fGetPiece(5, $laMove[0]), 1, 1)!='k') OR (substr($this->voBoard->fGetPiece(8, $laMove[0]), 1, 1)!='r') OR (substr($this->voBoard->fGetPiece(6, $laMove[0]), 1, 1)!='s') OR (substr($this->voBoard->fGetPiece(7, $laMove[0]), 1, 1)!='s') ) return FALSE; break; case '2': // castle - long if ((substr($this->voBoard->fGetPiece(5, $laMove[0]), 1, 1)!='k') OR (substr($this->voBoard->fGetPiece(1, $laMove[0]), 1, 1)!='r') OR (substr($this->voBoard->fGetPiece(2, $laMove[0]), 1, 1)!='s') OR (substr($this->voBoard->fGetPiece(3, $laMove[0]), 1, 1)!='s') OR (substr($this->voBoard->fGetPiece(4, $laMove[0]), 1, 1)!='s') ) return FALSE; break; case '5': // en passant selected // a) get color, get col // b) own pawn moved to 5th row, enemy behind them, from adj 4th // c) enemy pawn was at 2nd row last turn { // begin-case echocall('doing case 5', $T);
if (substr($lsPiece, 0, 2)=='lp') { echocall('was a lp', $T);
$lsBehind = $this->voBoard->fGetPiece($laMove[3], 4); echocall("Behind was $lsBehind", $T);
if ((substr($lsBehind, 0, 2)=='dp') AND ($laMove[2]==3)) { echocall ('en passant light called', $T); $laPriorBoard = $this->voGame->fGetCurrentBoard($liTurnNum-2); $loPriorBoard = new oBoard($laPriorBoard); $lsPriorPiece = $loPriorBoard->fGetPiece($laMove[3], 2); if ($lsBehind==$lsPriorPiece) return TRUE; else return FALSE; }//end-if } // end-if color
if (substr($lsPiece, 0, 2)=='dp') { echocall('was a dp', $T);
$lsBehind = $this->voBoard->fGetPiece($laMove[3], 5); echocall("Behind was $lsBehind", $T);
if ((substr($lsBehind, 0, 2)=='lp') AND ($laMove[2]==6)) { echocall ('en passant dark called', $T); $laPriorBoard = $this->voGame->fGetCurrentBoard($liTurnNum-2); $loPriorBoard = new oBoard($laPriorBoard); $lsPriorPiece = $loPriorBoard->fGetPiece($laMove[3], 7); if ($lsBehind==$lsPriorPiece) return TRUE; else return FALSE; }//end-if } // end-if color
else return FALSE; } // end-case break;
default: return TRUE; // drastic error, not a piece. break; }//end-switch
return TRUE; }//end-meth # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ }//end-class #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|