-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJacksOrBetter.js
104 lines (93 loc) · 2.5 KB
/
JacksOrBetter.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
var arrButtons = ['bet-bt', 'draw-bt'];
function GetButtons(callback) {
var buttons = new Array();
if (jQuery('#draw-bt').length > 0 && jQuery('#draw-bt').is(":enabled")) {
buttons[buttons.length] = arrButtons.indexOf('draw-bt');
}
if (jQuery('#bet-bt').length > 0 && jQuery('#bet-bt').is(":enabled")) {
buttons[buttons.length] = arrButtons.indexOf('bet-bt');
}
if (buttons.length == 0) {
setTimeout(function () {
GetButtons(callback);
}, 1000);
}
else {
callback(buttons);
}
}
function DoMove(data,callback)
{
if (data.move != -1) {
console.log(arrButtons[data.move]);
if (data.move == 1) {
console.log(data.hold);
$.each(data.hold, function (key, value) {
if (value == 1)
{
jQuery('#player-card-' + (key+1)).click();
}
});
}
jQuery('#' + arrButtons[data.move]).click();
callback();
}
else {
console.log('stoped');
//alert(data);
}
}
function ProccessMove()
{
GetButtons(function (buttons) {
var player = GetPlayersCards("player-cards");
console.log(player);
console.log(buttons);
GetBestMove(function (data) {
DoMove(data, function () {
setTimeout(ProccessMove, 2000);
});
}, buttons, player);
});
}
function GetPlayersCards(owner)
{
var arrCards = new Array();
$.each($('#'+owner+' div.card'), function (key, value) {
var elem = this;
var rank = $(elem).find('.rank').html();
var suit = $(elem).find('.suit').html();
if (suit == '♠') {
suit = 'S';
}
else if (suit == '♣') {
suit = 'C';
}
else if (suit == '♦') {
suit = 'D';
}
else {
suit = 'H';
}
arrCards[arrCards.length] = suit + "_" + rank;
});
return arrCards;
}
function GetBestMove(callback, buttons,player) {
var serviceURL = 'http://localhost:41164/home/JacksOrBetter?jsoncallback=?';
$.ajax({
dataType: "json",
traditional: true,
url: serviceURL,
data: { buttons: buttons, player: player },
success: function (data) {
callback(data);
}
});
}
function testCall() {
$.getJSON('http://localhost:41164/home/test?jsoncallback=?', function (data) {
alert(data);
});
}
ProccessMove();