-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_try.js
61 lines (51 loc) · 1.59 KB
/
client_try.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const socket = require('socket.io-client')('http://127.0.0.1:51234');
const movement = require('./min_max/evalueate_move')
const tournamentID = 12;
const user_name = 'Pascalito';
const current_time = new Date();
const board = [
[
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99
],
[
0, 99, 99, 0, 0, 0, 0, 99, 0,
0, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99
]
]
movement(board, 1)
socket.on('connect',function(){
// Client has connected to server
console.log("User " + user_name + " connected.");
socket.emit('signin', {
user_name: user_name,
tournament_id: tournamentID,
user_role: 'player'
});
});
socket.on('ready', function(data){
// Client waiting to be assigned
console.log("Last Move: " + current_time.getHours() + ":" + current_time.getMinutes() + ":" + current_time.getSeconds())
console.log(data.board)
socket.emit('play', {
player_turn_id: data.player_turn_id,
tournament_id: tournamentID,
game_id: data.game_id,
movement: movement(data.board, data.player_turn_id)
});
});
socket.on('finish', function(data){
// Game has finished
console.log("----- Game " + data.game_id + " has finished -----");
console.log("Ready to play again!");
// Start again!
socket.emit('player_ready', {
tournament_id: tournamentID,
game_id: data.game_id,
player_turn_id: data.player_turn_id
});
});