/** * Chess Piece logic calculates legal moves or just makes them from a fen or arrays */ class chessPieceLogic{ /** Connects to the webservice @var soapClient */ public $ws; public $serverId; /** This is to call hidden functions */ public function __call($name,$arguments){ return $this->ws->__soapCall($name, $arguments); } /** This is to call functions using old code */ public function __soapCall($name,$arguments){ return $this->ws->__soapCall($name, $arguments); } /** This is to set cookie values functions */ public function setCookies($cookies_csv){ if($cookies_csv != null){ $splitCookies = explode(",",$cookies_csv); foreach($splitCookies as $currentCookie){ $subSplit= explode("=",$currentCookie); $this->ws->__setCookie($subSplit[0], $subSplit[1]); } } } /** * This is the fen when the game starts * This replaces the old version */ public function startNewGame(){ return $this->ws->__soapCall("startNewGame",array()); } /** Gets the current fen */ public function generate_fen(){ return $this->ws->__soapCall("generate_fen",array()); } /** Set a fen! */ public function set_fen($fen){ return $this->ws->__soapCall("set_fen",array($fen)); } /** Check to see if you can connect to webservice. Also returns the class name for smarter connection. You do not really need to call this, makes connection easier. */ public function __construct($cookies_csv=null){ $this->serverId="http://soap.peterdownie.com/webServices/chessPieceLogic/server.php"; $this->ws = new SoapClient(null,array("uri"=>"$this->serverId","location"=>"$this->serverId")); $this->setCookies($cookies_csv); return $this->ws->__soapCall("__construct",array()); } /** get the array white and then the array black in 1 and 2 in feed This is just here for legacy reasons, you should really just return the FEN */ public function getPieceArray(){ return $this->ws->__soapCall("getPieceArray",array()); } /** sets the pieces of white and black. You could alos use startingPieces instead if the game has not started. You may now pass null and it will leave the pieces as they are for that color. If you leave both null you will get a warning. Turn is either 1 or 2 Castling availablity must be KQkq(any combination in order) or - It now be blank for neither */ public function setPieceArray($white,$black,$turn='1',$castlingAvialabilty='',$enpassant_move='',$halfMoveClock='',$fullMoveClock=''){ return $this->ws->__soapCall("setPieceArray",array($white,$black,$turn,$castlingAvialabilty,$enpassant_move,$halfMoveClock,$fullMoveClock)); } /** MakeAMove takes an input and makes a move regardless if the move is legal or not. Used to return piece value. Now returns array of data." . ". See tech. * Update! Returned to using 1 or 2 * Setting real to false disables this function. This is used to find moves that are illegal, which would otherwise write the moves as made! */ public function makeAMove($color,$move,$real='1'){ return $this->ws->__soapCall("makeAMove",array($color,$move,$real)); } /** MultiMove takes a move csv and calls makeAMove with the values. More Info in Tech. Returns an output see tech specs. */ public function multiMove($color,$moves_csv){ return $this->ws->__soapCall("multiMove",array($color,$moves_csv)); } /** netMoves calculates all legal moves and returns an array of moves. Returns in feed a2-a3,a2-a4,a7-a8=Q,e1-f1. Gets rid of illegal moves when the king is in check and cannot castle as well as enabling enpassante. The csv Moves is for enpassante and such, it does not calculate from there as this uses addition computer resources. */ public function netMoves($color,$csvMoves){ return $this->ws->__soapCall("netMoves",array($color,$csvMoves)); } /** Takes a move and makes sure that it is legal, does not check all of the other moves to save processing power checkForLegalMove takes a move in the format square1-square2, ie a2-a3... The net moves takes a value from netMoves in an array. If the value is in the array than the move is indeed legal. This function returns 1 of 3 values, the first is LEGAL_MOVE and the second is ILLEGAL_MOVE. IF there are no moves than CHECKMATE or STALEMATE is given and the game is over */ public function checkForLegalMove($color,$move,$csvMoves){ return $this->ws->__soapCall("checkForLegalMove",array($color,$move,$csvMoves)); } }