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
cc081adf
Commit
cc081adf
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: basic implementation of advanced strategy seems to be working
parent
c3f764fc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/hepia/AIPlayer.java
+160
-0
160 additions, 0 deletions
src/main/java/hepia/AIPlayer.java
src/main/java/hepia/GameManager.java
+1
-1
1 addition, 1 deletion
src/main/java/hepia/GameManager.java
with
161 additions
and
1 deletion
src/main/java/hepia/AIPlayer.java
+
160
−
0
View file @
cc081adf
package
hepia
;
package
hepia
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* AIPlayer
* AIPlayer
...
@@ -15,6 +17,113 @@ public class AIPlayer implements IPlayer {
...
@@ -15,6 +17,113 @@ 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
<>();
static
{
Map
<
Integer
,
Action
>
handWeight8orLess
=
new
HashMap
<>();
// value 1 should be ACE!
for
(
int
i
=
1
;
i
<=
10
;
i
++)
{
handWeight8orLess
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
handWeight9
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
2
;
i
++)
{
handWeight9
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
3
;
i
<=
6
;
i
++)
{
handWeight9
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
handWeight9
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
handWeight10
=
new
HashMap
<>();
handWeight10
.
put
(
1
,
Action
.
HIT
);
for
(
int
i
=
2
;
i
<=
9
;
i
++)
{
handWeight10
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
handWeight10
.
put
(
10
,
Action
.
HIT
);
Map
<
Integer
,
Action
>
handWeight11
=
new
HashMap
<>();
handWeight11
.
put
(
1
,
Action
.
HIT
);
for
(
int
i
=
2
;
i
<=
10
;
i
++)
{
handWeight11
.
put
(
i
,
Action
.
DOUBLEDOWN
);
}
Map
<
Integer
,
Action
>
handWeight12
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
3
;
i
++)
{
handWeight12
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
4
;
i
<=
6
;
i
++)
{
handWeight12
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
handWeight12
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
handWeight13
=
new
HashMap
<>();
handWeight13
.
put
(
1
,
Action
.
HIT
);
for
(
int
i
=
2
;
i
<=
6
;
i
++)
{
handWeight13
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
handWeight13
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
handWeight14
=
new
HashMap
<>();
handWeight14
.
put
(
1
,
Action
.
HIT
);
for
(
int
i
=
2
;
i
<=
6
;
i
++)
{
handWeight14
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
7
;
i
<=
10
;
i
++)
{
handWeight14
.
put
(
i
,
Action
.
HIT
);
}
Map
<
Integer
,
Action
>
handWeight15
=
new
HashMap
<>();
handWeight15
.
put
(
1
,
Action
.
HIT
);
for
(
int
i
=
2
;
i
<=
6
;
i
++)
{
handWeight15
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
7
;
i
<=
9
;
i
++)
{
handWeight15
.
put
(
i
,
Action
.
HIT
);
}
handWeight15
.
put
(
10
,
Action
.
SURRENDER
);
Map
<
Integer
,
Action
>
handWeight16
=
new
HashMap
<>();
handWeight16
.
put
(
1
,
Action
.
SURRENDER
);
for
(
int
i
=
2
;
i
<=
6
;
i
++)
{
handWeight16
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
7
;
i
<=
8
;
i
++)
{
handWeight16
.
put
(
i
,
Action
.
HIT
);
}
for
(
int
i
=
9
;
i
<=
10
;
i
++)
{
handWeight16
.
put
(
i
,
Action
.
SURRENDER
);
}
Map
<
Integer
,
Action
>
handWeight17OrAbove
=
new
HashMap
<>();
for
(
int
i
=
1
;
i
<=
10
;
i
++)
{
handWeight17OrAbove
.
put
(
i
,
Action
.
STAND
);
}
for
(
int
i
=
1
;
i
<=
8
;
i
++)
{
strategyTable
.
put
(
i
,
handWeight8orLess
);
}
strategyTable
.
put
(
9
,
handWeight9
);
strategyTable
.
put
(
10
,
handWeight10
);
strategyTable
.
put
(
11
,
handWeight11
);
strategyTable
.
put
(
12
,
handWeight12
);
strategyTable
.
put
(
13
,
handWeight13
);
strategyTable
.
put
(
14
,
handWeight14
);
strategyTable
.
put
(
15
,
handWeight15
);
strategyTable
.
put
(
16
,
handWeight16
);
for
(
int
i
=
17
;
i
<
21
;
i
++)
{
strategyTable
.
put
(
i
,
handWeight17OrAbove
);
}
}
@Override
@Override
public
boolean
hasSplitHand
()
{
public
boolean
hasSplitHand
()
{
if
(
splittedHand
!=
null
)
{
if
(
splittedHand
!=
null
)
{
...
@@ -153,7 +262,58 @@ public class AIPlayer implements IPlayer {
...
@@ -153,7 +262,58 @@ public class AIPlayer implements IPlayer {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
}
public
void
advancedStrategy
(
Deck
currentGame
,
Hand
croupierHand
)
{
while
(
this
.
getHand
().
computeHandValue
()
<
21
)
{
this
.
displayPlayerHand
();
for
(
Card
card
:
this
.
getHand
())
{
if
(
card
.
getRankName
().
equals
(
"As"
))
{
if
(
this
.
getHand
().
computeHandValue
()
+
10
<=
21
)
{
System
.
out
.
println
(
"AI assigned the value 11 to the ace"
);
card
.
setWeight
(
11
);
if
(
this
.
getHand
().
computeHandValue
()
==
21
)
{
break
;
}
}
}
}
Map
<
Integer
,
Action
>
inner
=
strategyTable
.
get
(
this
.
getHand
().
computeHandValue
());
Action
act
=
inner
.
get
(
croupierHand
.
computeHandValue
());
switch
(
act
)
{
case
HIT:
System
.
out
.
println
(
"AI drew a new card"
);
this
.
getHand
().
addToHand
(
currentGame
.
removeFromDeck
());
break
;
case
STAND:
System
.
out
.
println
(
"AI has decided to stand"
);
return
;
case
DOUBLEDOWN:
System
.
out
.
println
(
"AI player has doubled its bet"
);
this
.
setDoubledBet
(
true
);
case
SPLIT:
// TODO
// System.out.println("AI player has doubled its bet");
// this.setDoubledBet(true);
break
;
case
SURRENDER:
System
.
out
.
println
(
"AI has decided to surrender"
);
return
;
default
:
break
;
}
try
{
Thread
.
sleep
(
4000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
src/main/java/hepia/GameManager.java
+
1
−
1
View file @
cc081adf
...
@@ -355,7 +355,7 @@ public class GameManager {
...
@@ -355,7 +355,7 @@ public class GameManager {
for
(
AIPlayer
aiPlayer
:
this
.
aiPlayers
)
{
for
(
AIPlayer
aiPlayer
:
this
.
aiPlayers
)
{
System
.
out
.
println
(
aiPlayer
);
System
.
out
.
println
(
aiPlayer
);
aiPlayer
.
basic
Strategy
(
this
.
currentGame
);
aiPlayer
.
advanced
Strategy
(
this
.
currentGame
,
this
.
croupier
.
getHand
()
);
}
}
// Croupier's turn
// Croupier's turn
...
...
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