Exemplo n.º 1
0
 public function main()
 {
     $piece = new Piece(new StateTwo());
     //Starts on One
     $piece->moveDown();
     //Goes to Three
     $piece->moveRight();
     //Goes to Four
     $piece->moveUp();
     //Goes to Two
     $piece->moveLeft();
     //Goes to One
     $piece->moveLeft();
     //Error
     $piece->moveLeft();
     //Error
     $piece->moveUp();
     //Error
     $piece->moveRight();
     //Goes to Two
     $piece->moveUp();
     //Error
 }
Exemplo n.º 2
0
 /**
  * Resolve the conflict when given a sply on either side.
  *
  * @param  \Salpakan\Game\Piece  $attacking
  * @param  \Salpakan\Game\Piece  $defending
  * @return \Salpakan\Game\Piece|array  Piece/s that's lost the battle.
  */
 private function resolveSpyConflict(Piece $attacking, Piece $defending)
 {
     if ($attacking->is('spy') && $defending->is('spy')) {
         return [$attacking, $defending];
     }
     if ($attacking->is('spy') && $defending->is('private')) {
         return $attacking;
     }
     if ($attacking->is('private') && $defending->is('spy')) {
         return $defending;
     }
     if ($defending->is('spy')) {
         return $attacking;
     }
     return $defending;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Piece::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 4
0
 function __construct($xin, $yin, $board, $white)
 {
     parent::__construct($xin, $yin, $board);
     $this->setColor($white);
     if ($white) {
         $this->typecode = ChessBoard::$WHITEKING;
     } else {
         $this->typecode = ChessBoard::$BLACKKING;
     }
 }
Exemplo n.º 5
0
<?php

// presets table
//
$user = User::byUsername('alexander');
$preset = $user->createPreset('Flag First');
$piece = Piece::bySlug($slug);
$preset->assign($piece, $x = 0, $y = 0);
Exemplo n.º 6
0
echo $form->labelEx($model, 'component_name');
?>
		<?php 
echo $form->textField($model, 'component_name', array('size' => 40, 'maxlength' => 255));
?>
		<?php 
echo $form->error($model, 'component_name');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'piece_id');
?>
		<?php 
echo $form->dropDownlist($model, 'piece_id', CHtml::listData(Piece::model()->findAll(), 'id', 'piece_name'), array('empty' => '-- select piece --'));
?>
		<?php 
echo $form->error($model, 'piece_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'rate_price');
?>
		<?php 
echo $form->textField($model, 'rate_price');
?>
		<?php 
echo $form->error($model, 'rate_price');
Exemplo n.º 7
0
 /**
  * Checks whether the given piece follow a long castle move
  * 
  * @param Piece $piece the piece to check
  * @param string $sq1 current position of the piece
  * @param string $sq2 destination of the piece
  * 
  * @return bool returns true if 'long castle' is valid or false otherwise
  */
 private function _is_valid_long_castle($piece, $sq1, $sq2)
 {
     $player1 = $this->players[0];
     $player2 = $this->players[1];
     $player = $piece->get_player();
     $board = $this->board;
     $tsq = $player == $player1 ? "c1" : "c8";
     if ($sq2 != $tsq) {
         return false;
     }
     if ($piece->moved()) {
         $this->message = ucfirst($player) . "'s king has already moved";
         return false;
     }
     $rook == NULL;
     if ($player == $player1) {
         $rook = $board->get_piece_at("a1");
     } else {
         $rook = $board->get_piece_at("a8");
     }
     if ($rook == false || $rook->moved()) {
         $this->message = ucfirst($player) . "'s queenside rook has already moved";
         return false;
     }
     $rook_sq = $player == $player1 ? "a1" : "a8";
     $king_sq = $player == $player1 ? "e1" : "e8";
     $board_c = clone $board;
     $board_c->set_piece_at($king_sq, NULL);
     $board_c->set_piece_at($rook_sq, NULL);
     if ($board_c->line_is_open($king_sq, $rook_sq) == false) {
         $this->message = "There are pieces between " . ucfirst($player) . "'s king and rook";
         return false;
     }
     return true;
 }