summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2009-10-10 22:58:44 +0200
committerNicolas Schodet2009-10-10 22:58:44 +0200
commit4160b0ebb6fffd8dba558ce66ba83e71a09614c1 (patch)
treeeaaeab12c5d5a2669256f24d0b378f7fb0658bf6
parente903a50c6bef35a283bd1cc1894a40fd1fb5eae2 (diff)
host/simu: add table for Eurobot 2010, closes #101
-rw-r--r--host/simu/model/table_eurobot2010.py89
-rw-r--r--host/simu/view/table_eurobot2010.py129
2 files changed, 218 insertions, 0 deletions
diff --git a/host/simu/model/table_eurobot2010.py b/host/simu/model/table_eurobot2010.py
new file mode 100644
index 00000000..c9c10d0b
--- /dev/null
+++ b/host/simu/model/table_eurobot2010.py
@@ -0,0 +1,89 @@
+# 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 2010."""
+import simu.model.table
+from random import randint
+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 = (randint (1, 9), randint (1, 4))
+ self.cards = cards
+ # Well, this is a boring write only code which create every elements.
+ # Put corn on the table.
+ self.corns = [ ]
+ corns_pos = ((0, 5), (0, 3), (0, 1), (1, 4), (1, 2), (1, 0), (2, 3),
+ (2, 1), (3, 0), (3, 2))
+ black_corns_cards = (
+ (None, (1, 4), (0, 4), (2, 4), (2, 3), (0, 3), (1, 3), (1, 6),
+ (0, 6), (2, 6)),
+ (None, (5, 8), (7, 8), (5, 9), (7, 9)),
+ )
+ black_corns = (black_corns_cards[0][cards[0]] +
+ black_corns_cards[1][cards[1]])
+ for i in xrange (len (corns_pos)):
+ if corns_pos[i][0] == 3:
+ poss = (corns_pos[i], )
+ else:
+ poss = (corns_pos[i], (6 - corns_pos[i][0], corns_pos[i][1]))
+ for pos in poss:
+ corn = RoundObstacle (25, 1)
+ corn.pos = (150 + pos[0] * 450, 128 + pos[1] * 250)
+ corn.black = i in black_corns
+ self.corns.append (corn)
+ # Put tomatos on the table.
+ self.tomatos = [ ]
+ tomatos_pos = ((0, 4), (0, 2), (1, 3), (1, 1), (2, 2), (2, 0), (3, 3),
+ (3, 1))
+ for tomato_pos in tomatos_pos:
+ if tomato_pos[0] == 3:
+ poss = (tomato_pos, )
+ else:
+ poss = (tomato_pos, (6 - tomato_pos[0], tomato_pos[1]))
+ for pos in poss:
+ tomato = RoundObstacle (50, 1)
+ tomato.pos = (150 + pos[0] * 450, 128 + pos[1] * 250)
+ self.tomatos.append (tomato)
+ # Put oranges.
+ self.oranges = [ ]
+ self.oranges_pos = ((250 - 80, 70), (250 - 80 - 55, 70 + 75),
+ (250 - 55, 70 + 75 + 50), (250 - 80, 70 + 75 + 50 + 100),
+ (250 - 80 - 55, 70 + 75 + 50 + 100 + 75),
+ (250 - 55, 70 + 75 + 50 + 100 + 75 + 50))
+ for pos in self.oranges_pos:
+ orange = RoundObstacle (50, 2)
+ orange.pos = (1500 - pos[0], 2100 - pos[1])
+ self.oranges.append (orange)
+ orange = RoundObstacle (50, 2)
+ orange.pos = (1500 + pos[0], 2100 - pos[1])
+ self.oranges.append (orange)
+ # Add everything to obstacles.
+ self.obstacles += self.corns
+ self.obstacles += self.tomatos
+ self.obstacles += self.oranges
+
diff --git a/host/simu/view/table_eurobot2010.py b/host/simu/view/table_eurobot2010.py
new file mode 100644
index 00000000..2ef8de1f
--- /dev/null
+++ b/host/simu/view/table_eurobot2010.py
@@ -0,0 +1,129 @@
+# 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.
+#
+# }}}
+"""Eurobot 2010 table."""
+from simu.inter.drawable import Drawable
+from simu.utils.trans_matrix import TransMatrix
+from math import pi
+
+GREEN = '#00ad00'
+RED = '#f80404'
+BLUE = '#0000ee'
+BLACK = '#404040'
+YELLOW = '#e5e500'
+WHITE = '#c9c9d0'
+ORANGE = '#f6991f'
+PLEXI = '#99bbbb'
+BROWN = '#99bbbb'
+
+corn_attr = { False: dict (fill = WHITE),
+ True: dict (fill = BLACK) }
+
+class Round (Drawable):
+
+ def __init__ (self, onto, attr, model):
+ Drawable.__init__ (self, onto)
+ self.attr = attr
+ self.model = model
+ self.model.register (self.__notified)
+ self.__notified ()
+
+ def __notified (self):
+ self.pos = self.model.pos
+ self.update ()
+
+ def draw (self):
+ self.reset ()
+ if self.pos:
+ self.trans_translate (self.pos)
+ self.draw_circle ((0, 0), self.model.radius, **self.attr)
+ Drawable.draw (self)
+
+class Corn (Round):
+ pass
+
+class Tomato (Round):
+ pass
+
+class Orange (Round):
+ pass
+
+class Table (Drawable):
+ """The table and its elements."""
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ for e in model.corns:
+ Corn (self, corn_attr[e.black], e)
+ for e in model.tomatos:
+ Tomato (self, dict (fill = RED), e)
+ for e in model.oranges:
+ Orange (self, dict (fill = ORANGE), e)
+
+ def draw_both (self, primitive, *args, **kargs):
+ """Draw a primitive on both sides."""
+ primitive (*args, **kargs)
+ primitive (*((3000 - x, y) for x, y in args), **kargs)
+
+ def draw (self):
+ # Redraw.
+ self.reset ()
+ # Table.
+ self.draw_rectangle ((-22, -22), (3000 + 22, 2100 + 22), fill = BLACK)
+ self.draw_rectangle ((0, -22), (3000, 2100), fill = GREEN)
+ self.draw_rectangle ((500, -22), (2500, 0), fill = BLACK)
+ self.draw_rectangle ((0, 2100 - 500), (500, 2100), fill = BLUE)
+ self.draw_rectangle ((3000 - 500, 2100 - 500), (3000, 2100), fill = YELLOW)
+ # Axes.
+ self.draw_line ((0, 200), (0, 0), (200, 0), arrow = 'both')
+ # Bags.
+ self.draw_rectangle ((-20, -22), (500 + 20, -250 - 20), fill = YELLOW)
+ self.draw_rectangle ((3000 + 20, -22), (3000 - 500 - 20, -250 - 20), fill = BLUE)
+ self.draw_both (self.draw_rectangle, (0, -22), (500, -250), fill = PLEXI)
+ # Beacons.
+ self.draw_both (self.draw_rectangle, (-22, 2100 + 22), (-22 - 80, 2100 + 22 + 80), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (-22, 1050 - 40), (-22 - 80, 1050 + 40), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (-22, -80 - 22), (-22 - 80, -22), fill = BLACK)
+ # Hill.
+ self.draw_rectangle ((750 - 100, 2100), (3000 - 750 + 100, 2100 - 500), fill = WHITE)
+ self.draw_both (self.draw_line, (750, 2100), (750, 2100 - 500))
+ self.draw_both (self.draw_line, (750 + 500, 2100), (750 + 500, 2100 - 500))
+ self.draw_rectangle ((740, 2100 - 500), (3000 - 740, 2100 - 500 - 22), fill = BLACK)
+ self.draw_both (self.draw_line, (740 + 500, 2100 - 500), (740 + 500, 2100 - 500 - 22))
+ self.draw_both (self.draw_line, (740, 2100 + 22), (740, 2100))
+ self.draw_both (self.draw_line, (740 + 500, 2100 + 22), (740 + 500, 2100))
+ # Trees.
+ for pos in self.model.oranges_pos:
+ self.draw_circle ((1500 - pos[0], 2100 - pos[1]), 25)
+ self.draw_circle ((1500 + pos[0], 2100 - pos[1]), 25)
+ # Children.
+ Drawable.draw (self)
+
+if __name__ == '__main__':
+ from simu.inter.inter import Inter
+ import simu.model.table_eurobot2010 as model
+ app = Inter ()
+ m = model.Table ()
+ Table (app.table_view, m)
+ app.mainloop ()