JSFiddle - React, Tailwind, and code Playground
by Mykola Senyk
HTML
<script src="http://premium-api.com/jscourse/rb_plain.js"></script>
<h1>Reversi</h1>
JavaScript
var randomPlayer = function() {
// TODO put your logic here
// sample of function that make a move
function makeMove(isBlack) {
var o = [];
for (var i=0; i<64; i++) { o.push(i); }
for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
// find correct move
for (var i=0; i<64; i++) {
var col = String.fromCharCode(o[i] % 8 + 97);
var row = Math.floor(o[i]/8) + 1;
if ( isMoveValid(col, row) ) {
return { col: col, row: row};
}
}
}
return {
name: "Random",
move: makeMove,
init: function() {
//TODO new game has started
},
afterGame: function() {
//TODO after game has ended
}
};
};
/**
* Created by vpetlya on 1/29/15.
* [email protected]
*/
var potentialPlayer = function () {
const CharToNumber = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8};
const NumberToChar = [0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
const COLORS = ['w', 'b', 'w'];
const CellsWeight = [
[5, 0.75, 1.25, 1.2, 1.2, 1.25, 0.75, 5 ],
[0.75, 0.25, 0.8, 1, 1, 0.8, 0.25, 0.75],
[1.25, 0.8, 1.25, 1, 1, 1.25, 0.8, 1.25],
[1.2, 1, 1.1, 1, 1, 1.1, 1, 1.2 ],
[1.2, 1, 1.1, 1, 1, 1.1, 1, 1.2 ],
[1.25, 0.8, 1.25, 1, 1, 1.25, 0.8, 1.25],
[0.75, 0.25, 0.8, 1, 1, 0.8, 0.25, 0.75],
[5, 0.75, 1.25, 1.2, 1.2, 1.25, 0.75, 5 ]
];
var myColor = null;
var root;
var turn = 1;
var bestChain;
var Prediction = function (parent, parentIdx) {
var color;
var board;
var width;
var depth;
var ownDisks;
var enemyDisks;
var emptyCells;
var predictionCount = 0;
var realTurn = null;
/*var _maxAccumulatedOwn=null;
var...