Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
oop
project
Commits
74eb1c56
Commit
74eb1c56
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: continuing to implement the advanced version of the ai player
parent
cc081adf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/hepia/AIPlayer.java
+153
-36
153 additions, 36 deletions
src/main/java/hepia/AIPlayer.java
with
153 additions
and
36 deletions
src/main/java/hepia/AIPlayer.java
+
153
−
36
View file @
74eb1c56
...
@@ -17,7 +17,8 @@ public class AIPlayer implements IPlayer {
...
@@ -17,7 +17,8 @@ public class AIPlayer implements IPlayer {
private
int
insuranceBet
;
private
int
insuranceBet
;
private
boolean
hasDoubledBet
;
private
boolean
hasDoubledBet
;
private
static
Map
<
Integer
,
Map
<
Integer
,
Action
>>
strategyTable
=
new
HashMap
<>();
private
static
Map
<
Integer
,
Map
<
Integer
,
Action
>>
strategyTableWithoutAces
=
new
HashMap
<>();
private
static
Map
<
Integer
,
Map
<
Integer
,
Action
>>
strategyTableWithAces
=
new
HashMap
<>();
static
{
static
{
Map
<
Integer
,
Action
>
handWeight8orLess
=
new
HashMap
<>();
Map
<
Integer
,
Action
>
handWeight8orLess
=
new
HashMap
<>();
...
@@ -107,23 +108,121 @@ public class AIPlayer implements IPlayer {
...
@@ -107,23 +108,121 @@ public class AIPlayer implements IPlayer {
}
}
for
(
int
i
=
1
;
i
<=
8
;
i
++)
{
for
(
int
i
=
1
;
i
<=
8
;
i
++)
{
strategyTable
.
put
(
i
,
handWeight8orLess
);
strategyTable
WithoutAces
.
put
(
i
,
handWeight8orLess
);
}
}
strategyTable
.
put
(
9
,
handWeight9
);
strategyTable
WithoutAces
.
put
(
9
,
handWeight9
);
strategyTable
.
put
(
10
,
handWeight10
);
strategyTable
WithoutAces
.
put
(
10
,
handWeight10
);
strategyTable
.
put
(
11
,
handWeight11
);
strategyTable
WithoutAces
.
put
(
11
,
handWeight11
);
strategyTable
.
put
(
12
,
handWeight12
);
strategyTable
WithoutAces
.
put
(
12
,
handWeight12
);
strategyTable
.
put
(
13
,
handWeight13
);
strategyTable
WithoutAces
.
put
(
13
,
handWeight13
);
strategyTable
.
put
(
14
,
handWeight14
);
strategyTable
WithoutAces
.
put
(
14
,
handWeight14
);
strategyTable
.
put
(
15
,
handWeight15
);
strategyTable
WithoutAces
.
put
(
15
,
handWeight15
);
strategyTable
.
put
(
16
,
handWeight16
);
strategyTable
WithoutAces
.
put
(
16
,
handWeight16
);
for
(
int
i
=
17
;
i
<
21
;
i
++)
{
for
(
int
i
=
17
;
i
<
21
;
i
++)
{
strategyTable
.
put
(
i
,
handWeight17OrAbove
);
strategyTable
WithoutAces
.
put
(
i
,
handWeight17OrAbove
);
}
}
}
}
static
{
Map
<
Integer
,
Action
>
ace8orHigher
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
10
;
i
++)
{
ace8orHigher
.
put
(
i
,
Action
.
STAND
);
}
Map
<
Integer
,
Action
>
ace7
=
new
HashMap
<>();
ace7
.
put
(
1
,
Action
.
HIT
);
ace7
.
put
(
2
,
Action
.
STAND
);
for
(
int
i
=
3
;
i
<=
6
;
i
++)
{
ace7
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
8
;
i
++)
{
ace7
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
9
;
i
<=
10
;
i
++)
{
ace7
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
ace6
=
new
HashMap
<>();
ace6
.
put
(
1
,
Action
.
HIT
);
ace6
.
put
(
2
,
Action
.
HIT
);
for
(
int
i
=
3
;
i
<=
6
;
i
++)
{
ace6
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
ace6
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
ace5
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
3
;
i
++)
{
ace5
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
4
;
i
<=
6
;
i
++)
{
ace5
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
ace5
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
ace4
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
3
;
i
++)
{
ace4
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
4
;
i
<=
6
;
i
++)
{
ace4
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
ace4
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
ace3
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
4
;
i
++)
{
ace3
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
5
;
i
<=
6
;
i
++)
{
ace3
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
ace3
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
ace2
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
4
;
i
++)
{
ace2
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
5
;
i
<=
6
;
i
++)
{
ace2
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
ace2
.
put
(
i
,
Action
.
HIT
);
}
strategyTableWithAces
.
put
(
8
,
ace7
);
strategyTableWithAces
.
put
(
18
,
ace7
);
strategyTableWithAces
.
put
(
7
,
ace6
);
strategyTableWithAces
.
put
(
17
,
ace6
);
strategyTableWithAces
.
put
(
6
,
ace5
);
strategyTableWithAces
.
put
(
16
,
ace5
);
strategyTableWithAces
.
put
(
5
,
ace4
);
strategyTableWithAces
.
put
(
15
,
ace4
);
strategyTableWithAces
.
put
(
4
,
ace3
);
strategyTableWithAces
.
put
(
14
,
ace3
);
strategyTableWithAces
.
put
(
3
,
ace2
);
strategyTableWithAces
.
put
(
13
,
ace2
);
strategyTableWithAces
.
put
(
19
,
ace8orHigher
);
strategyTableWithAces
.
put
(
20
,
ace8orHigher
);
strategyTableWithAces
.
put
(
21
,
ace8orHigher
);
}
@Override
@Override
public
boolean
hasSplitHand
()
{
public
boolean
hasSplitHand
()
{
if
(
splittedHand
!=
null
)
{
if
(
splittedHand
!=
null
)
{
...
@@ -265,12 +364,15 @@ public class AIPlayer implements IPlayer {
...
@@ -265,12 +364,15 @@ public class AIPlayer implements IPlayer {
}
}
public
void
advancedStrategy
(
Deck
currentGame
,
Hand
croupierHand
)
{
public
void
advancedStrategy
(
Deck
currentGame
,
Hand
croupierHand
)
{
boolean
handContainsAce
=
false
;
Map
<
Integer
,
Action
>
innerMap
;
while
(
this
.
getHand
().
computeHandValue
()
<
21
)
{
while
(
this
.
getHand
().
computeHandValue
()
<
21
)
{
this
.
displayPlayerHand
();
this
.
displayPlayerHand
();
for
(
Card
card
:
this
.
getHand
())
{
for
(
Card
card
:
this
.
getHand
())
{
if
(
card
.
getRankName
().
equals
(
"As"
))
{
if
(
card
.
getRankName
().
equals
(
"As"
))
{
handContainsAce
=
true
;
if
(
this
.
getHand
().
computeHandValue
()
+
10
<=
21
)
{
if
(
this
.
getHand
().
computeHandValue
()
+
10
<=
21
)
{
System
.
out
.
println
(
"AI assigned the value 11 to the ace"
);
System
.
out
.
println
(
"AI assigned the value 11 to the ace"
);
card
.
setWeight
(
11
);
card
.
setWeight
(
11
);
...
@@ -278,12 +380,23 @@ public class AIPlayer implements IPlayer {
...
@@ -278,12 +380,23 @@ public class AIPlayer implements IPlayer {
if
(
this
.
getHand
().
computeHandValue
()
==
21
)
{
if
(
this
.
getHand
().
computeHandValue
()
==
21
)
{
break
;
break
;
}
}
// System.out.println("AI drew a new card");
// this.getHand().addToHand(currentGame.removeFromDeck());
}
}
}
}
}
}
Map
<
Integer
,
Action
>
inner
=
strategyTable
.
get
(
this
.
getHand
().
computeHandValue
());
if
(
handContainsAce
)
{
Action
act
=
inner
.
get
(
croupierHand
.
computeHandValue
());
innerMap
=
strategyTableWithAces
.
get
(
this
.
getHand
().
computeHandValue
());
}
else
{
innerMap
=
strategyTableWithoutAces
.
get
(
this
.
getHand
().
computeHandValue
());
}
System
.
out
.
println
(
"DEBUG("
+
handContainsAce
+
"): innerMap = "
+
innerMap
);
if
(
innerMap
.
containsKey
(
croupierHand
.
computeHandValue
()))
{
Action
act
=
innerMap
.
get
(
croupierHand
.
computeHandValue
());
switch
(
act
)
{
switch
(
act
)
{
case
HIT:
case
HIT:
...
@@ -296,6 +409,9 @@ public class AIPlayer implements IPlayer {
...
@@ -296,6 +409,9 @@ public class AIPlayer implements IPlayer {
case
DOUBLEDOWN:
case
DOUBLEDOWN:
System
.
out
.
println
(
"AI player has doubled its bet"
);
System
.
out
.
println
(
"AI player has doubled its bet"
);
this
.
setDoubledBet
(
true
);
this
.
setDoubledBet
(
true
);
System
.
out
.
println
(
"AI drew a new card"
);
this
.
getHand
().
addToHand
(
currentGame
.
removeFromDeck
());
break
;
case
SPLIT:
case
SPLIT:
// TODO
// TODO
// System.out.println("AI player has doubled its bet");
// System.out.println("AI player has doubled its bet");
...
@@ -307,6 +423,7 @@ public class AIPlayer implements IPlayer {
...
@@ -307,6 +423,7 @@ public class AIPlayer implements IPlayer {
default
:
default
:
break
;
break
;
}
}
}
try
{
try
{
Thread
.
sleep
(
4000
);
Thread
.
sleep
(
4000
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment