Permalink
Browse files

fixed pawn movement

  • Loading branch information...
1 parent 7e97d3e commit 0338e7ec59f188b36b3ddd90d181b7693461635f @tux21b committed Apr 5, 2012
Showing with 32 additions and 10 deletions.
  1. +14 −2 chess.css
  2. +6 −4 chess.go
  3. +1 −0 chess.html
  4. +11 −4 chess.js
View
@@ -9,7 +9,7 @@ body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 18px;
- color: #333333;
+ color: #222222;
background-color: #ffffff;
margin: 0;
}
@@ -44,6 +44,9 @@ header p.intro {
width: 60%;
text-align: right;
margin: 0;
+ font-weight: bold;
+ font-style: italic;
+ color: #444;
}
footer {
@@ -67,6 +70,15 @@ aside {
user-select: none;
}
+#clocks {
+ margin-bottom: 1em;
+}
+
#history {
- margin-top: 1em;
+ margin-top: .5em;
+}
+
+label {
+ font-weight: bold;
+ color: #333;
}
View
@@ -65,11 +65,13 @@ func (b *Board) ValidMove(ax, ay, bx, by int) bool {
case KNIGHT * WHITE, KNIGHT * BLACK:
return (ax-bx)*(ax-bx)+(ay-by)*(ay-by) == 5
case PAWN * WHITE:
- return ax == bx && (ay+1 == by || (ay == 1 && by == 3)) ||
- ((ax-bx)*(ax-bx) == 1 && ay+1 == by && b[by*SIZE+bx] < 0)
+ return (ax == bx && (ay+1 == by || (ay == 1 && by == 3)) &&
+ b[by*SIZE+bx] == EMPTY) || ((ax-bx)*(ax-bx) == 1 &&
+ ay+1 == by && b[by*SIZE+bx] != EMPTY)
case PAWN * BLACK:
- return ax == bx && (ay-1 == by || (ay == 6 && by == 4)) ||
- ((ax-bx)*(ax-bx) == 1 && ay+1 == by && b[by*SIZE+bx] > 0)
+ return (ax == bx && (ay-1 == by || (ay == 6 && by == 4)) &&
+ b[by*SIZE+bx] == EMPTY) || ((ax-bx)*(ax-bx) == 1 &&
+ ay-1 == by && b[by*SIZE+bx] != EMPTY)
case BISHOP * WHITE, BISHOP * BLACK:
return (ax-bx)*(ax-bx) == (ay-by)*(ay-by) && b.freeWay(ax, ay, bx, by)
case ROOK * WHITE, ROOK * BLACK:
View
@@ -22,6 +22,7 @@ <h1>ChessBuddy</h1>
Your browser does not support the canvas element.
</canvas>
+ <label id="l_history" for="history">history</label>
<div id="history">
</div>
</aside>
View
@@ -93,13 +93,14 @@ ChessGame.prototype.render = function() {
}
/* draw clocks */
- this.renderClock(0, 0, 130, 0, (this.color != 0) && ((this.turn & 1) == 1));
- this.renderClock(150, 0, 130, 0.25, (this.color != 0) && ((this.turn & 1) == 0));
+ this.renderClock(0, 0, 130, 0, 1);
+ this.renderClock(150, 0, 130, 0.25, -1);
};
-ChessGame.prototype.renderClock = function(x, y, size, t, active) {
+ChessGame.prototype.renderClock = function(x, y, size, t, color) {
var ctx = this.clocks_ctx;
- ctx.fillStyle = "#cccccc";
+ var active = (this.color != 0) && ((this.turn & 1) == (color > 0 ? 1 : 0));
+ ctx.fillStyle = "#cfcfd1";
ctx.beginPath();
ctx.arc(x+0.5*size, y+0.5*size, 0.5*size, 0, Math.PI*2, true);
ctx.closePath();
@@ -124,6 +125,12 @@ ChessGame.prototype.renderClock = function(x, y, size, t, active) {
y+0.5*size-0.475*size*Math.cos(t*Math.PI));
ctx.closePath();
ctx.stroke();
+
+ ctx.fillStyle = "#888";
+ ctx.font = 'bold 12pt "Helvetica Neue", Helvetica, Arial, sans-serif';
+ ctx.textAlign = "center";
+ ctx.textBaseline = "middle";
+ ctx.fillText(color > 0 ? "white" : "black", x+0.5*size, y+0.7*size);
}

0 comments on commit 0338e7e

Please sign in to comment.