summaryrefslogtreecommitdiff
path: root/host/simu/model/table_eurobot2011.py
blob: c9c1d193d289bf1118112e7c69ce72cafd25533e (plain)
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
# simu - Robot simulation. {{{
#
# Copyright (C) 2009 Nicolas Schodet
#
# APBTeam:
#        Web: http://apbteam.org/
#      Email: team AT apbteam DOT org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# }}}
"""Table model for Eurobot 2011."""
import simu.model.table
from random import randrange
from simu.model.round_obstacle import RoundObstacle

class Table (simu.model.table.Table):

    def __init__ (self, cards = None):
        simu.model.table.Table.__init__ (self)
        # Draw cards.
        if cards is None:
            cards = [ randrange (20) for i in xrange (3) ]
        self.cards = cards
        def pos (card):
            king_pos = card // 4
            queen_pos = card % 4
            if queen_pos >= king_pos:
                queen_pos += 1
            return (king_pos, queen_pos)
        # Well, this is a boring write only code which create every elements.
        self.pawns = [ ]
        # Put pawns in green zones.
        green_pos = pos (cards[0])
        for i in xrange (5):
            if i == green_pos[0]:
                kind = 'king'
            elif i == green_pos[1]:
                kind = 'queen'
            else:
                kind = 'pawn'
            pawn = RoundObstacle (100, 1)
            pawn.pos = (200, 10 + 280 * (5 - i))
            pawn.kind = kind
            self.pawns.append (pawn)
            pawn = RoundObstacle (100, 1)
            pawn.pos = (3000 - 200, 10 + 280 * (5 - i))
            pawn.kind = kind
            self.pawns.append (pawn)
        # Put pawns in playing zone.
        kind = 'pawn'
        for j in xrange (2):
            play_pos = pos (cards[2 - j])
            for i in xrange (5):
                if i in play_pos:
                    pawn = RoundObstacle (100, 1)
                    pawn.pos = (1500 - 350 * (1 + j), 350 * (5 - i))
                    pawn.kind = kind
                    self.pawns.append (pawn)
                    pawn = RoundObstacle (100, 1)
                    pawn.pos = (1500 + 350 * (1 + j), 350 * (5 - i))
                    pawn.kind = kind
                    self.pawns.append (pawn)
        # Put center pawn.
        kind = 'pawn'
        pawn = RoundObstacle (100, 1)
        pawn.pos = (1500, 350 * 3)
        pawn.kind = kind
        self.pawns.append (pawn)
        # Add everything to obstacles.
        self.obstacles += self.pawns