-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_choosing.jl
121 lines (113 loc) · 3.84 KB
/
action_choosing.jl
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
using Printf
using DataFrames
include("utils.jl")
include("playing_actions.jl")
function choose_playing_action(player_state, policy)
"""
Takes in the state of a player's hand and their policy
Returns the card they are playing
Currently, this is assuming they always will play. Need to know when to transition to betting mode.
"""
cards, opp_state = player_state_as_tuple(player_state)
skull = 1
flowers = 3
for i in 1:4
#the skull has already been played
if cards[i] == 2
skull -= 1
end
if cards[i] == 1
flowers -= 1
end
end
if policy == 0
return aggressive_play(skull, flowers)
elseif policy == 1
return random_play(skull, flowers)
elseif policy == 2
return flower_play(skull, flowers)
end
end
function choose_betting_action(player_state, cur_bet)
#2 optons: pass or increase
# There are two main reasons a player would want to pass.
# They have laid down a skull so they **know** they can't be successful
# They have enough uncertainty about other players cards that they do not **think** they can be successful
cards, opp_state = player_state_as_tuple(player_state)
skull = false
for i in 1:4
#we have already played the skull
if cards[i] == 2
skull = true
end
end
if skull == true
#pass almost all the time..
return 13
end
#choose to increase bet
#todo, this is a bad strategy... we need to have some number that is telling us how many we think we can get..
#so like if that number is 3 and the bet is at 3 we wouldn't want to increase
# add in check so we don't bet more than number of cards
@printf("opp state is %d\n", opp_state)
@printf("cards are %d, %d, %d, %d\n", cards[1], cards[2], cards[3], cards[4])
our_cards = findlast(!isequal(0), cards)
if iszero(cards)
our_cards = 0
end
num_cards_on_board = opp_state + our_cards
if cur_bet >= num_cards_on_board
return 13
end
return cur_bet+1
end
function choose_flipping_action(cur_turn, board_state, beta_flips)
"""
Takes in board_state
Returns the player whose card will be flipped next
"""
#if a player has cards in front of them, they must flip their own.
if board_state[cur_turn, 1] > 0
return cur_turn
else
#can choose any player it wants... probably want to do this as a beta or dirichlet..
#but for now it's random...
num_players = 4
exp = [0.0 for r in 1:4]
#if we do not have proper checks to make sure there is definitely
#a player who has a card to flip, this could be infinite
if count(!iszero(board_state)) == 0
@printf("Something is wrong, board empty before all cards flipped\n")
return -1
end
for i in 1:num_players
if i != cur_turn
alpha = beta_flips[i,1]
beta = beta_flips[i,2]
expectation = alpha/(alpha+beta)
exp[i] = expectation
end
end
for i in 1:num_players-1
maxval = maximum(exp)
player = cur_turn
for (i,x) in enumerate(exp)
if x == maxval
player = i
break
end
end
# player = [i for (i, x) in enumerate(exp) if x == maxval]
#we know this will never be true if the number is the current player
opponent_stack = board_state[player, 1]
if opponent_stack[1] > 0
print("Chose player to flip")
print(player[1])
return player
end
exp[player] = 0.0
end
@printf("Something is wrong, board empty before all cards flipped\n")
return -1
end
end