Exemple #1
0
 /**
  * Validate a move
  * @param array parsed move array from {@link _parseMove()}
  * @return true|PEAR_Error
  * @throws GAMES_CHESS_ERROR_MOVE_MUST_CAPTURE
  * @access protected
  */
 function _validMove($move)
 {
     list($type, $info) = each($move);
     if ($this->_capturePossible() && ($type == GAMES_CHESS_CASTLE || $this->_board[$info['square']] == $info['square'])) {
         if ($type == GAMES_CHESS_CASTLE) {
             $san = $info == 'K' ? 'O-O' : 'O-O-O';
         } else {
             $san = $info['piece'] . $info['disambiguate'] . $info['takes'] . $info['square'];
         }
         return $this->raiseError(GAMES_CHESS_ERROR_MOVE_MUST_CAPTURE, array('san' => $san));
     }
     return parent::_validMove($move);
 }
 function _validMove($move)
 {
     list($type, $info) = each($move);
     reset($move);
     if ($type == GAMES_CHESS_PIECEPLACEMENT) {
         if (!$this->_captured[$this->_move][$info['piece']]) {
             return $this->raiseError(GAMES_CHESS_ERROR_NOPIECES_TOPLACE, array('color' => $this->_move == 'W' ? 'B' : 'W', 'piece' => $info['piece']));
         }
         if ($this->_board[$info['square']] != $info['square']) {
             return $this->raiseError(GAMES_CHESS_ERROR_PIECEINTHEWAY, array('square' => $info['square']));
         }
         return true;
     } else {
         return parent::_validMove($move);
     }
 }