-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
53 lines (45 loc) · 2.1 KB
/
play.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
# -*- coding: utf-8 -*-
from __future__ import division
import logging
from collections import namedtuple, OrderedDict
import operator
import cards
from player import Player
from board import Board
from bots import SimpleBot, Human
example_players_names_M = ['Chris', 'Tom', 'Marcus', 'Bob', 'Adam', 'Iris']
example_players_names_F = ['Iris', 'Eve', 'Julie', 'Lisa', 'Mary', 'Tara']
example_players_names = example_players_names_M + example_players_names_F
def rewrite_player_type(player_type):
if type(player_type) == str:
if player_type.upper() == 'H' or player_type.upper() == 'HUMAN':
return Human
else:
print player_type, type(player_type)
raise ValueError('Not recognized player type. Get: "{}", should be: "human" or type of bot.'.format(player_type))
elif issubclass(player_type, SimpleBot) or player_type == Human:
return player_type
else:
raise ValueError('Not recognized bot type. Get: {}, should be subclass of: SimpleBot.'.format(player_type.__name__))
def play(players_num, types_of_players, players_names=None, cards_names=None, start_gold=6):
if players_names == None:
players_names = example_players_names[:players_num]
if cards_names == None:
cards_names = ['King'] * players_num
types_of_players = map(rewrite_player_type, types_of_players)
if players_num < 3:
raise ValueError('Not enough players (min: 3).')
if players_num > len(players_names):
raise ValueError('Not enough names of players (min: {}).'.format(players_num))
if players_num > len(cards_names):
raise ValueError('Not enough types of cards (min: {}).'.format(players_num))
if players_num != len(types_of_players):
raise ValueError('Not enough types of players (should be: {}).'.format(players_num))
mygame = Board(players_num, types_of_players, players_names, cards_names, start_gold)
end_of_game = False
while not end_of_game:
end_of_game, history_of_game = mygame.next_step()
return history_of_game
if __name__ == "__main__":
import doctest
doctest.testmod()