-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPawn.php
More file actions
68 lines (66 loc) · 1.34 KB
/
Copy pathPawn.php
File metadata and controls
68 lines (66 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once( "ChessPiece.php" );
class Pawn extends ChessPiece
{
//------------------------------------------------------------------
public function __construct( $color, $startingSquare )
{
if( $color == "White" )
{
$legalMoves = array(
new Move( 0, 1 ) //Exact movement
);
$legalAttacks = array(
new Move( 1, 1 ),
new Move( -1, 1 )
);
}
else
{
$legalMoves = array(
new Move( 0, -1 )
);
$legalAttacks = array(
new Move( 1, -1 ), //Exact movements
new Move( -1, -1 )
);
}
parent::__construct( "Pawn", //name
$color,
$startingSquare,
$legalMoves,
$legalAttacks,
1 //starting value
);
}
//------------------------------------------------------------------
protected function isLegalMove( $move )
{
if( $this->numberOfMoves == 0 &&
$move->isEqualSpaces( new Move( 0, 2 ) ) )
{
return true;
}
foreach( $this->legalMoves as $legalMove )
{
if( $legalMove->isEqualMove( $move ) )
{
return true;
}
}
return false;
}
//------------------------------------------------------------------
protected function isLegalAttack( $move )
{
foreach( $this->legalAttacks as $legalAttack )
{
if( $legalAttack->isEqualMove( $move ) )
{
return true;
}
}
return false;
}
} //Pawn
?>