Skip to content
Browse files

it now seems to be working sweet

Signed-off-by: Tim Henderson <tim.tadh@gmail.com>
  • Loading branch information...
1 parent 599bc3d commit eb49adcf088ae024a9cbe08c52afa2f7546aa58f @timtadh timtadh committed Apr 29, 2009
Showing with 17 additions and 9 deletions.
  1. +9 −5 resolution_engine.py
  2. +8 −4 stored_procedures/pieces and orders/orders_for_user.sql
View
14 resolution_engine.py
@@ -29,6 +29,7 @@ def execute(pce_id):
order = db.callproc('orders_for_piece', pce_id)
if order and order[0]['order_type'] == 1:
db.callproc('move_piece', pce_id, order[0]['destination'])
+ print 'executed'
class graph(object):
@@ -185,7 +186,7 @@ def dfs_visit(v):
dfs_visit(v)
- def step_two(self):
+ def step_two(self, dont=False):
dislodged = set()
exe = set()
color = [0 for i in self.pieces]
@@ -202,7 +203,7 @@ def dfs_visit(v):
if self.sup(u) > max_sup: max_sup = self.sup(u)
color[v] = 2
- #print v, self.sup(v), max_sup, self.sup(v) > max_sup
+ print v, self.sup(v), max_sup, self.sup(v) > max_sup
if self.sup(v) > max_sup:
exe.add(v)
for u in self.adj(v):
@@ -220,9 +221,9 @@ def dfs_visit(v):
print exe - dislodged
for pce in list(exe - dislodged):
- execute(pce)
+ if not dont: execute(self.pieces[pce])
for pce in list(dislodged):
- dislodge(pce, self.piece_info[self.pieces[pce]]['ter_id'])
+ if not dont: dislodge(self.pieces[pce], self.piece_info[self.pieces[pce]]['ter_id'])
print dislodged
def resolve(gam_id):
@@ -232,5 +233,8 @@ def resolve(gam_id):
g.step_two()
if __name__ == '__main__':
- pass
+ g = graph(1)
+ g.step_one()
+ #graph_algorithms._print_matrix(g.pce_m)
+ g.step_two(True)
#g.create_order_graph()
View
12 stored_procedures/pieces and orders/orders_for_user.sql
@@ -6,7 +6,7 @@ DROP PROCEDURE IF EXISTS orders_for_user $$
CREATE PROCEDURE orders_for_user(IN gid INT(11), IN uid VARCHAR(64))
BEGIN
- SELECT piece.pce_id, orders.order_type, order_type.order_text,
+ SELECT DISTINCT piece.pce_id, orders.order_type, order_type.order_text,
orders.destination AS destination, territory.name AS dst_name,
order_type.destination AS has_dst
FROM piece
@@ -16,9 +16,13 @@ BEGIN
ON (orders.pce_id = piece.pce_id)
INNER JOIN order_type
ON (orders.order_type = order_type.odt_id)
- INNER JOIN territory
- ON (orders.destination = territory.ter_id OR orders.destination IS NULL)
- WHERE country.usr_id = uid AND country.gam_id = gid;
+ LEFT JOIN territory
+ ON (orders.destination = territory.ter_id)
+ INNER JOIN game
+ ON (country.gam_id = game.gam_id)
+ WHERE country.usr_id = uid AND country.gam_id = gid
+ AND game.gam_season = orders.gam_season
+ AND game.gam_year = orders.gam_year;
END
$$

0 comments on commit eb49adc

Please sign in to comment.
Something went wrong with that request. Please try again.