-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhanabi.py
70 lines (63 loc) · 2.24 KB
/
hanabi.py
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
#!/usr/bin/python
#-*- coding: utf-8 -*-
from deck import *
from table import *
from player import *
from bcolor import *
import colorama
class Hanabi:
"""
Hanabi is the main class in the project.
Static Attributes :
deck (Deck) : the deck of cards in the game
table (Table) : the table on which the game is played
players (List<Player>) : the list of players
"""
deck = Deck()
deck.shuffle() # deck is shuffled here for code portability. Should be sorted if re-shuffled with a seed.
table = Table()
players = []
@classmethod
def initPlayers(cls, nbPlayer, nbHand, playerTypeArray):
""" Player that try to play playable card.
"""
Hanabi.newGame()
playersNumber = nbPlayer
handSize = nbHand
playersType = playerTypeArray
for i in range(playersNumber):
playerType = playersType[i]
if playerType == 1:
cls.players.append(Player(handSize))
elif playerType == 2:
cls.players.append(PlayerRandom(handSize))
elif playerType == 3:
cls.players.append(PlayerRandomPlus(handSize))
elif playerType == 4:
cls.players.append(PlayerRandomPlusPlus(handSize))
elif playerType == 5:
from keras.models import load_model
nn = load_model("NeuralNetPlayer.pkl")
cls.players.append(PlayerNet(handSize, model=nn))
cls.players[i].drawFrom(cls.deck)
@classmethod
def newGame(cls):
cls.deck = Deck()
cls.deck.shuffle()
cls.table = Table()
cls.players = []
@classmethod
def promptPlayerType(cls):
print(colorama.Fore.LIGHTBLUE_EX + "Human(1), random(2), random+(3) or random++(4)? " + Bcolor.END, end='')
playerType = input()
return int(playerType)
@classmethod
def promptHandSize(cls):
print(colorama.Fore.LIGHTBLUE_EX + "Hand size : " + Bcolor.END, end='')
handSize = input()
return int(handSize)
@classmethod
def promptPlayers(cls):
print(colorama.Fore.LIGHTBLUE_EX + "How many players? " + Bcolor.END, end='')
playersNumber = input()
return int(playersNumber)