Skip to content

Commit

Permalink
Blind and random modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrucru committed Feb 3, 2017
1 parent 9c52930 commit 2c696b8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 14 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,15 @@ The option gives the pawn a higher static valuation when it has left its initial

The impact is on the valuation, not on the performances.

- **AntiCrux.options.variant.whiteBoard**
- **AntiCrux.options.variant.pieces**

This human-related option renders the board with white pieces only. It may be used to reduce the readability of the game but the players must still follow the basic rules.
This human-related option renders the board differently. It may be used to reduce the readability of the game but the players must still follow the basic rules. The possible modes are :

- 0 : normal
- 1 : only white pieces
- 2 : only black pieces
- 3 : blind
- 4 : random

The export to FEN and PGN is not impacted.

Expand Down Expand Up @@ -418,7 +424,7 @@ node --expose-gc nodejs_demo_solve.js
- November 11th 2016 - Creation of the project
- December 25th 2016 - Version 0.1.0
- Initial set of features
- January 29th 2017 - Version 0.2.0
- February 3rd 2017 - Version 0.2.0
- Library: AntiCrux.prototype.getMoves renamed as AntiCrux.prototype.getMovesHtml
- Library: new mandatory parameter for AntiCrux.prototype.highlightMoves
- UI: highlighted target cells when requesting a detailed hint
Expand Down Expand Up @@ -454,6 +460,7 @@ node --expose-gc nodejs_demo_solve.js
- Library: improvement of the deep analysis
- Library: new parameter for AntiCrux.prototype.isEndGame
- Library: the minimal search depth is now 1 (previously 3)
- UI: blind and random modes


### License
Expand Down
65 changes: 60 additions & 5 deletions anticrux.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
// 1n1qk1n1/r1pp1p1r/1p6/8/8/1P4P1/2PK1P1P/1N3BNR w - - Mate in 10 to be found (Na3)
// rnb4r/p1pk3p/5P2/8/1p6/1P3P2/P1PNP1P1/R3KBN1 b - - Mate in 10 to be found (Ke7)
// rn2k2r/ppp2p1p/5p2/8/8/N6P/PPPKPP1P/R1B2BNR b - - Mate in 11 to be found (b5)
// 6n1/p7/2B2p2/8/8/4K3/P1P2PPR/RN6 w - - Mate in 12 to be found (Rh6)
// rnb4K/pppp1k1p/5p2/2b5/4n3/8/8/8 b - - Mate in 13 to be found
// rnb1kb1r/p1pp1ppp/7n/4P3/1p5R/1P6/P1P1PPP1/RNBQKBN1 w - - Mate in 15 to be found (Bh6)
// 4k2r/pppn2pp/4p3/8/8/N3PN2/PPP1K1P1/R1B5 w - - Mate to find g4 and Nb5 (Ne5-g4)
Expand Down Expand Up @@ -1226,7 +1227,7 @@ AntiCrux.prototype.getMovesHtml = function(pPlayer, pNode) {
};

AntiCrux.prototype.toHtml = function(pNode) {
var x, y, rotated, color, abc, output;
var x, y, rotated, color, abc, owner, output;

//-- Self
if (pNode === undefined)
Expand All @@ -1246,7 +1247,33 @@ AntiCrux.prototype.toHtml = function(pNode) {
for (x=(rotated?7:0) ; (!rotated&&(x<8)) || (rotated&&(x>=0)) ; (rotated?x--:x++))
{
color = 1 - color;
output += '<div class="AntiCrux-board-cell-' + (this._highlight.indexOf(8*y+x) != -1 ? 'hl' : color) + ' AntiCrux-board-piece-' + (this.options.variant.whiteBoard && (pNode.owner[8*y+x] != this.constants.owner.none) ? this.constants.owner.white : pNode.owner[8*y+x]) + pNode.piece[8*y+x] + '" data-xy="' + abc[x] + (8-y) + '">';
switch (this.options.variant.pieces)
{
case 1:
owner = (pNode.owner[8*y+x] != this.constants.owner.none ? this.constants.owner.white : pNode.owner[8*y+x]);
break;
case 2:
owner = (pNode.owner[8*y+x] != this.constants.owner.none ? this.constants.owner.black : pNode.owner[8*y+x]);
break;
case 3:
owner = this.constants.owner.none;
break;
case 4:
if (pNode.owner[8*y+x] == this.constants.owner.none)
owner = this.constants.owner.none;
else
{
if (Math.floor(100*Math.random()) % 2 == 0)
owner = this.constants.owner.black;
else
owner = this.constants.owner.white;
}
break;
default:
owner = pNode.owner[8*y+x];
break;
}
output += '<div class="AntiCrux-board-cell-' + (this._highlight.indexOf(8*y+x) != -1 ? 'hl' : color) + ' AntiCrux-board-piece-' + owner + pNode.piece[8*y+x] + '" data-xy="' + abc[x] + (8-y) + '">';
if (this.options.board.debugCellId)
output += y + '/' + x + '<br/>' + (8*y+x);
output += '</div>';
Expand Down Expand Up @@ -1348,7 +1375,7 @@ AntiCrux.prototype.toFen = function(pNode) {
AntiCrux.prototype.toText = function(pNode) {
// Use one of the fonts "Chess" available at www.dafont.com

var x, y, rotated, i, b, car, buffer;
var x, y, rotated, i, b, car, buffer, owner;

//-- Self
if (pNode === undefined)
Expand All @@ -1372,8 +1399,36 @@ AntiCrux.prototype.toText = function(pNode) {
buffer += '$';
}

//- Owner
switch (this.options.variant.pieces)
{
case 1:
owner = (pNode.owner[i] != this.constants.owner.none ? this.constants.owner.white : pNode.owner[i]);
break;
case 2:
owner = (pNode.owner[i] != this.constants.owner.none ? this.constants.owner.black : pNode.owner[i]);
break;
case 3:
owner = this.constants.owner.none;
break;
case 4:
if (pNode.owner[i] == this.constants.owner.none)
owner = this.constants.owner.none;
else
{
if (Math.floor(100*Math.random()) % 2 == 0)
owner = this.constants.owner.black;
else
owner = this.constants.owner.white;
}
break;
default:
owner = pNode.owner[i];
break;
}

//- Nature of the position
switch (this.options.variant.whiteBoard && (pNode.owner[i] != this.constants.owner.none) ? this.constants.owner.white : pNode.owner[i])
switch (owner)
{
case this.constants.owner.none:
car = (b ? '+' : '*');
Expand Down Expand Up @@ -1634,7 +1689,7 @@ AntiCrux.prototype._init = function() {
variant : {
promoteQueen : false, //TRUE only promotes pawns as queen
activePawns : false, //TRUE makes the pawns stronger for the valuation once they are moved, and are consequently less mobile
whiteBoard : false //TRUE makes the board fully white
pieces : 0 //Variant for the pieces: 0=normal, 1=white pieces, 2=black pieces, 3=blind, 4=random
},
board : {
rotated : false, //TRUE rotates the board at 180°
Expand Down
2 changes: 1 addition & 1 deletion anticrux.min.js

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ <h2>Artificial intelligence</h2>
<option value="7">Oyster</option>
</select>
</p>
<p><label for="acui_option_maxdepth">Maximal depth :</label> <input class="AntiCrux-ui-option" id="acui_option_maxdepth" type="number" min="1"/></p>
<p><label for="acui_option_maxnodes">Maximal nodes :</label> <input class="AntiCrux-ui-option" id="acui_option_maxnodes" type="number" min="0" step="100"/></p>
<p><label for="acui_option_maxdepth">Maximal depth :</label> <input class="AntiCrux-ui-option" id="acui_option_maxdepth" type="number" min="1" /></p>
<p><label for="acui_option_maxnodes">Maximal nodes :</label> <input class="AntiCrux-ui-option" id="acui_option_maxnodes" type="number" min="0" step="100" title="Zero is infinite" /></p>
<p><label for="acui_option_wholenodes">Maximize the nodes</label> <input class="AntiCrux-ui-option" id="acui_option_wholenodes" type="checkbox" /></p>
<p><label for="acui_option_minimizeliberty">Minimize the liberty</label> <input class="AntiCrux-ui-option" id="acui_option_minimizeliberty" type="checkbox" /></p>
<p><label for="acui_option_maxreply">Maximal number of replies :</label> <input class="AntiCrux-ui-option" id="acui_option_maxreply" type="range" value="1" min="1" max="10" /></p>
Expand Down Expand Up @@ -224,7 +224,15 @@ <h2>Board</h2>
<h2>Variant</h2>
<p><label for="acui_option_promotequeen">Promote pawns as queen</label> <input class="AntiCrux-ui-option" id="acui_option_promotequeen" type="checkbox" /></p>
<p><label for="acui_option_activepawns">Active pawns</label> <input class="AntiCrux-ui-option" id="acui_option_activepawns" type="checkbox" /></p>
<p><label for="acui_option_whiteboard">White board</label> <input class="AntiCrux-ui-option AntiCrux-ui-option-refresh" id="acui_option_whiteboard" type="checkbox" /></p>
<p><label for="acui_option_pieces">Pieces :</label>
<select class="AntiCrux-ui-option AntiCrux-ui-option-refresh" id="acui_option_pieces">
<option value="0">Normal</option>
<option value="1">White pieces</option>
<option value="2">Black pieces</option>
<option value="3">Blind</option>
<option value="4">Random</option>
</select>
</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -317,7 +325,7 @@ <h1>Information</h1>
//-- Variant
$('#acui_option_promotequeen').prop('checked', ai.options.variant.promoteQueen);
$('#acui_option_activepawns').prop('checked', ai.options.variant.activePawns);
$('#acui_option_whiteboard').prop('checked', ai.options.variant.whiteBoard);
$('#acui_option_pieces').val(ai.options.variant.pieces).change();
}

function acui_reset_ui(pResetPlayer) {
Expand Down Expand Up @@ -447,6 +455,9 @@ <h1>Information</h1>

//-- Determines the position for the provided index
rewind = new AntiCrux();
rewind.copyOptions(ai);
if (rewind.options.variant.pieces == 3)
rewind.options.variant.pieces = 0;
if (!rewind.loadFen(ai.getInitialPosition()))
return false;
for (i=0 ; i<=index ; i++)
Expand Down Expand Up @@ -925,7 +936,7 @@ <h1>Information</h1>
//-- Variant
ai.options.variant.promoteQueen = $('#acui_option_promotequeen').prop('checked');
ai.options.variant.activePawns = $('#acui_option_activepawns').prop('checked');
ai.options.variant.whiteBoard = $('#acui_option_whiteboard').prop('checked');
ai.options.variant.pieces = parseInt($('#acui_option_pieces').val());
return true;
});

Expand Down

0 comments on commit 2c696b8

Please sign in to comment.