Skip to content

Commit

Permalink
Version working w/ the hackathon server
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelq committed Feb 10, 2017
1 parent e3e4c70 commit 40538a4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Logs
*.log

# Dependencies
node_modules/
13 changes: 10 additions & 3 deletions ai.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* Configuration */
const room = '';
const team = '';

// État
let grid;
let direction;
Expand Down Expand Up @@ -25,7 +29,7 @@ function setGrid(grid, x, y, value) {
}
}

function createGrid(config) {
function start(config) {
grid = Array(config.h).fill().map(() => Array(config.w).fill(0));

// Joueurs
Expand Down Expand Up @@ -192,7 +196,7 @@ function alphaBeta(grid, me, them, alpha, beta, depth, firstMove) {
return [alpha, bestMove];
}

function nextMove(prevMoves) {
function next(prevMoves) {
const startTime = process.hrtime();

if (prevMoves.length) {
Expand Down Expand Up @@ -226,7 +230,7 @@ function nextMove(prevMoves) {
return direction;
}

function victory(winnerID) {
function end(winnerID) {
if (winnerID === me.id) {
console.log('Match gagné');
} else if (winnerID === them.id) {
Expand All @@ -235,3 +239,6 @@ function victory(winnerID) {
console.log('Match nul');
}
}

// Ne pas modifier
module.exports = { room, team, start, next, end };
48 changes: 0 additions & 48 deletions lib.js

This file was deleted.

21 changes: 0 additions & 21 deletions nodelib.js

This file was deleted.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"start": "node tron.js"
},
"dependencies": {
"socket.io-client": "^1.7.2"
}
}
5 changes: 0 additions & 5 deletions run.sh

This file was deleted.

26 changes: 26 additions & 0 deletions tron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const io = require('socket.io-client');
const ai = require('./ai');

const socket = io('http://localhost:1337');

socket.on('connect', function () {
socket.emit('join', ai.room, ai.team);
console.log('Lien vers le match : http://localhost:1337/' + (ai.room || 'null'));
});

socket.on('start', function (config) {
ai.start(config);
});

socket.on('next', function (prevMoves) {
socket.emit('move', ai.next(prevMoves));
});

socket.on('end', function (winnerID) {
ai.end(winnerID);
process.exit();
});

socket.on('disconnect', function () {
process.exit();
});

0 comments on commit 40538a4

Please sign in to comment.