This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute vec4 instancePosition; | |
attribute float instanceAngle; | |
varying vec2 vUV; | |
void main(){ | |
vUV = uv; | |
vec3 rotatedPosition = position; | |
rotatedPosition.x = cos( instanceAngle ) * position.x - sin( instanceAngle ) * position.y; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backpropagate(node, result) { | |
let tmpNode = node; | |
while(tmpNode !== null) { | |
tmpNode.state.visits++; | |
if (result != tmpNode.state.board.DRAW) { | |
if (tmpNode.state.player === result) { | |
tmpNode.state.wins++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simulate(node) { | |
let state = node.state.clone(); //Temp state | |
state.board = node.state.board.clone(); | |
//Play randomly until one player wins or game result in draw | |
while (!state.isTerminal) { | |
state.switchToNextPlayer(); | |
let action = state.getRandomAction(state.player); | |
state.applyAction(action); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
selectPromisingChild(node) { | |
while(!node.state.isTerminal && node.isFullyExpanded) { | |
node = this.uct.findBestChild(node); | |
} | |
return node; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findNextAction(board, player, iterations) { | |
let root = new Node(); | |
root.state = new NodeState(); | |
root.state.board = board; | |
root.state.player = 3 - player;//Opponent player is owner of root node | |
for (let i=0; i < iterations; i++) { | |
//1.Selection | |
let node = this.selectPromisingChild(root); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
define(function () { | |
class GmaeBoardRenderer{ | |
constructor(canvas, canvasSize){ | |
this.canvas = canvas; | |
this.ctx = canvas.getContext('2d'); | |
this.canvas.width = canvasSize; | |
this.canvas.height = canvasSize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requirejs(['gameboardrenderer'], | |
function (GmaeBoardRenderer) { | |
let player = 1; | |
let boardState = [0,0,0,0,0,0,0,0,0]; //Initial board state | |
let canvas = document.getElementById('board'); | |
let gbr = new GmaeBoardRenderer(canvas, 500); | |
//Render initial state (grid) | |
gbr.render(boardState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCellIndex(position){ | |
for (let x = 0;x < 3;x++) { | |
for (let y = 0;y < 3;y++) { | |
let xCordinate = x * this.cellSize; | |
let yCordinate = y * this.cellSize; | |
if ( | |
position.x >= xCordinate && position.x <= xCordinate + this.cellSize && | |
position.y >= yCordinate && position.y <= yCordinate + this.cellSize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getRelativeCursorPosition(event){ | |
var rect = this.canvas.getBoundingClientRect(); | |
return { | |
x: event.clientX - rect.left, | |
y: event.clientY - rect.top | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drawGrid(){ | |
let offset = 5; | |
let lineLenght = this.canvas.width - offset; | |
this.ctx.lineWidth = this.gridLineWidth; | |
this.ctx.lineCap = 'round'; | |
this.ctx.strokeStyle = this.gridLineStyle; | |
this.ctx.beginPath(); | |
//Horizontal lines | |
for (let y = 1;y <= 2;y++) { |
NewerOlder