-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
133 lines (118 loc) · 2.7 KB
/
cli.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict'
var Once = require('./once.js');
var win = [0,0]
var bot_path1
var bot_path2
var r_n =100
var r = 0
var detail = false
var full = false
var roundtime = 2
function arrcopy(ret,a){ // ret must be []
for(var x of a){
ret.push(x);
}
}
function callback(winner,_detail,_full,_r){
if(_r!=r){
return;
}else{
r++;
}
if(r>=r_n) return;
// console.log(detail)
// console.log(full)
console.log(winner,win)
win[winner]++
// console.log(win)
// console.log(score)
var log = ''
if(full){
log+=_full
log+='\n'
}
if(detail){
for(var x of _detail){
log += `[${x}],`
}
log+='\n'
}
log+= win+'\n'
// console.log(log)
$('#log').after('<pre>'+log+'</pre>');
run();
// setTimeout(function() {
// run();
// }, 100);
// var s = $('#log').val()
}
function run(){
var O = new Once(bot_path1,bot_path2,roundtime,detail,full,r)
O.run(callback)
}
function click_stop(){
if($('#btnstop').hasClass('disabled')) return;
r_n = 0;
$('#btnrun').removeClass('disabled');
$('#btnstop').addClass('disabled');
}
function click_clear(){
$('#flog').html('<div id="log"></div>')
}
function click_run(){
if($('#btnrun').hasClass('disabled')) return;
r = 0
win = [0,0]
$('#btnrun').addClass('disabled');
$('#btnstop').removeClass('disabled');
bot_path1 = '';
try{
bot_path1 = $('#inputPath1').get(0).files[0].path;
}catch(e){
var options = {
content: "Path1 error!",
style: "toast",
timeout: 3000
}
$.snackbar(options);
return;
}
bot_path2 = '';
try{
bot_path2 = $('#inputPath2').get(0).files[0].path;
}catch(e){
var options = {
content: "Path2 error!",
style: "toast",
timeout: 3000
}
$.snackbar(options);
return;
}
if(!bot_path1 || !bot_path2){
var options = {
content: "Please input AI path.",
style: "toast",
timeout: 3000
}
$.snackbar(options);
return;
}
detail = $('#detail').is(":checked")
full = $('#fulllog').is(":checked")
roundtime = parseInt($('#roundtime').val())
if(roundtime>=0 && roundtime <=100){
}else{
roundtime = 2
}
$('#roundtime').val(roundtime)
var roundnum = parseInt($('#roundnumber').val())
if(roundnum>=1 && roundnum <=10000){
} else{
roundnum = 100
}
$('#roundnumber').val(roundnum)
console.log(roundnum)
r_n = roundnum +1
run(detail,fulllog,roundtime)
}