From 7ff80b218d2a76a7ba60e1f07a4daf5655119f0b Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 18 Jan 2019 17:59:32 +0000 Subject: [PATCH 01/54] msgs: add order slot to DS instructions We now also require that the prepare message for a DS contains the order that is to be delivered. --- src/msgs/MachineInstructions.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/src/msgs/MachineInstructions.proto b/src/msgs/MachineInstructions.proto index 884ebc9e2..a7000fbd7 100644 --- a/src/msgs/MachineInstructions.proto +++ b/src/msgs/MachineInstructions.proto @@ -62,6 +62,7 @@ message PrepareInstructionBS { message PrepareInstructionDS { required uint32 gate = 1; + required uint32 order_id = 2; } message PrepareInstructionSS { From 1716d0a444c7579525cdcebef8b35b17a874d6ba Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Sun, 20 Jan 2019 13:30:45 +0000 Subject: [PATCH 02/54] rcll: store info about last delivered order in machine fact When a DS is prepared, also store the order ID that the DS was prepared for. This can later be used to check whether the correct product was delivered. --- src/games/rcll/facts.clp | 1 + src/games/rcll/production.clp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/games/rcll/facts.clp b/src/games/rcll/facts.clp index 4d2d7739d..080294760 100644 --- a/src/games/rcll/facts.clp +++ b/src/games/rcll/facts.clp @@ -71,6 +71,7 @@ (slot ds-gate (type INTEGER)) (slot ds-last-gate (type INTEGER)) + (slot ds-order (type INTEGER)) (slot ss-operation (type SYMBOL) (allowed-values STORE RETRIEVE)) (multislot ss-slot (type INTEGER) (cardinality 3 3)) ; meaning defined in llsf_msgs.SSSlot diff --git a/src/games/rcll/production.clp b/src/games/rcll/production.clp index 1799ecf41..b69340477 100644 --- a/src/games/rcll/production.clp +++ b/src/games/rcll/production.clp @@ -102,8 +102,9 @@ then (bind ?prepmsg (pb-field-value ?p "instruction_ds")) (bind ?gate (pb-field-value ?prepmsg "gate")) - (printout t "Prepared " ?mname " (gate: " ?gate ")" crlf) - (modify ?m (state PREPARED) (ds-gate ?gate) + (bind ?order (pb-field-value ?prepmsg "order_id")) + (printout t "Prepared " ?mname " (gate: " ?gate ", order: " ?order ")" crlf) + (modify ?m (state PREPARED) (ds-gate ?gate) (ds-order ?order) (mps-state AVAILABLE) (wait-for-product-since ?gt)) ;(wait-for-product-since ?gt)) else From b80965d98d559ca5c536bfb49d0dd9360010fd5b Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Sun, 20 Jan 2019 13:56:48 +0000 Subject: [PATCH 03/54] rcll: directly assert product-delivered fact on delivery at DS If the DS is in state PROCESSED, directly assert a product-delivered fact with the new confirmed slot set to FALSE. Previously, the fact was only created when a referee would enter a delivery into the refbox. As we already know which order was delivered, directly assert the fact to keep track of the order. This will require further changes in the processing of the order. --- src/games/rcll/facts.clp | 1 + src/games/rcll/production.clp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/games/rcll/facts.clp b/src/games/rcll/facts.clp index 080294760..390eb8ea1 100644 --- a/src/games/rcll/facts.clp +++ b/src/games/rcll/facts.clp @@ -221,6 +221,7 @@ (slot order (type INTEGER) (default 0)) (slot team (type SYMBOL) (allowed-values nil CYAN MAGENTA)) (slot delivery-gate (type INTEGER)) + (slot confirmed (type SYMBOL) (allowed-values FALSE TRUE) (default FALSE)) (slot base-color (type SYMBOL) (allowed-values BASE_RED BASE_SILVER BASE_BLACK)) (multislot ring-colors (type SYMBOL) (cardinality 0 3) (allowed-values RING_BLUE RING_GREEN RING_ORANGE RING_YELLOW)) diff --git a/src/games/rcll/production.clp b/src/games/rcll/production.clp index b69340477..f95a89671 100644 --- a/src/games/rcll/production.clp +++ b/src/games/rcll/production.clp @@ -398,9 +398,12 @@ (defrule prod-proc-state-processed-ds (declare (salience ?*PRIORITY_HIGH*)) (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?m <- (machine (name ?n) (mtype DS) (state PROCESSED) (proc-state ~PROCESSED)) + ?m <- (machine (name ?n) (mtype DS) (state PROCESSED) (proc-state ~PROCESSED) + (ds-order ?order) (team ?team)) => (printout t "Machine " ?n " finished processing, moving to output" crlf) + (assert (product-delivered (order ?order) (team ?team) (game-time ?gt) + (confirmed FALSE))) (modify ?m (state IDLE) (proc-state PROCESSED)) (mps-deliver (str-cat ?n)) ) From 6041924e3cf1ad42397b2c2d9c06f2343a9be2ed Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Sun, 20 Jan 2019 14:00:21 +0000 Subject: [PATCH 04/54] rcll: process SetOrderDelivered msg by setting the delivery to confirmed We already have the product-delivered field (which is now set when the DS is PROCESSED). If we receive a SetOrderDelivered message, just change the order from unconfirmed to confirmed. This will then trigger the scoring rules for that order. --- src/games/rcll/orders.clp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index f9df57af7..123346cde 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -41,19 +41,22 @@ (defrule order-recv-SetOrderDelivered (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (protobuf-msg (type "llsf_msgs.SetOrderDelivered") (ptr ?p) (rcvd-via STREAM) - (rcvd-from ?from-host ?from-port) (client-id ?cid)) + ?pf <- (protobuf-msg (type "llsf_msgs.SetOrderDelivered") (ptr ?p) (rcvd-via STREAM)) => - (bind ?id (pb-field-value ?p "order_id")) - (bind ?team (sym-cat (pb-field-value ?p "team_color"))) - (if (not (any-factp ((?o order)) (= ?o:id ?id))) + (if (not (do-for-fact + ((?pd product-delivered)) + (and (eq ?pd:order (pb-field-value ?p "order_id")) + (eq ?pd:team (sym-cat (pb-field-value ?p "team_color")))) + (eq ?pd:confirmed FALSE) + (printout t "Confirmed delivery of order " ?pd:order + " by team " ?pd:team crlf) + (modify ?pd (confirmed TRUE)))) then - (printout error "Received SetOrderDelivered for non-existing order " ?id crlf) - else - (do-for-fact ((?o order)) (= ?o:id ?id) - (assert (product-delivered (game-time ?gt) (order ?id) (team ?team))) - ) + (printout error "Received invalid SetOrderDelivered" + " (order " (pb-field-value ?p "order_id") + ", team " (pb-field-value ?p "team_color") ")" crlf) ) + (retract ?pf) ) From 0517d207a791a7a1bc9d7b17139cb01e0e2f688b Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Sun, 20 Jan 2019 14:34:53 +0000 Subject: [PATCH 05/54] rcll: always base scoring on order ID, not on colors Do not process SetOrderDeliveredByColor messages at all anymore. They are no longer necessary, because the order ID is always available since it is always contained in the DS prepare message. --- src/games/rcll/orders.clp | 158 +++++--------------------------------- 1 file changed, 18 insertions(+), 140 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 123346cde..8f573e44b 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -60,36 +60,10 @@ ) -(defrule order-recv-SetOrderDeliveredByColor - (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (protobuf-msg (type "llsf_msgs.SetOrderDeliveredByColor") (ptr ?p) (rcvd-via STREAM) - (rcvd-from ?from-host ?from-port) (client-id ?cid)) - => - (bind ?team (sym-cat (pb-field-value ?p "team_color"))) - (bind ?base-color (sym-cat (pb-field-value ?p "base_color"))) - (bind ?ring-colors (pb-field-list ?p "ring_colors")) - (bind ?cap-color (sym-cat (pb-field-value ?p "cap_color"))) - - (do-for-fact ((?m machine)) (and (eq ?m:mtype DS) (eq ?m:team ?team)) - ;(printout t "Product delivered: " ?gt " " ?team " " ?m:ds-last-gate " " - ; ?base-color " " ?ring-colors " " ?cap-color crlf) - (bind ?gate ?m:ds-last-gate) - (if (= ?gate 0) then (bind ?gate ?m:ds-gate)) - (assert (product-delivered (game-time ?gt) (team ?team) (delivery-gate ?gate) - (base-color ?base-color) (ring-colors ?ring-colors) (cap-color ?cap-color))) - (if (= ?m:ds-last-gate 0) - then - (modify ?m (ds-gate 0)) - else - (modify ?m (ds-last-gate 0)) - ) - ) -) - -(defrule order-delivered-correct-by-id +(defrule order-delivered-correct ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) - (order ?id&~0)) + (order ?id&~0) (confirmed TRUE)) ; the actual order we are delivering ?of <- (order (id ?id) (active TRUE) (complexity ?complexity) (delivery-gate ?dgate&:(or (eq ?gate 0) (eq ?gate ?dgate))) @@ -136,101 +110,18 @@ ) ) -(defrule order-delivered-by-color-invalid +(defrule order-delivered-invalid ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order 0) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color)) - (not (order (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color))) + ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?order)) + (not (order (id ?order))) => (retract ?pf) (assert (attention-message (team ?team) - (text (str-cat "Invalid Order delivered: " ?base-color " " - (implode$ ?ring-colors) " " ?cap-color)))) + (text (str-cat "Invalid order delivered by " ?team ": " + "no active order with ID " + ?order crlf)))) ) -(defrule order-delivered-correct-by-color - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) (order 0) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color)) - ; the actual order we are delivering - ?of <- (order (id ?id) (active TRUE) (complexity ?complexity) - (delivery-gate ?dgate&:(or (eq ?gate 0) (eq ?gate ?dgate))) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (quantity-requested ?q-req) - (quantity-delivered $?q-del&:(< (order-q-del-team ?q-del ?team) ?q-req)) - (delivery-period $?dp&:(>= ?gt (nth$ 1 ?dp))&:(<= ?gt (nth$ 2 ?dp)))) - - - ; There is no other order, which would score more points - (not (and - ; in-time, proper gate, open (q-del < q-req) - (order (id ?oid2&:(<> ?oid2 ?id)) (active TRUE) - (delivery-gate ?dgate2&:(or (eq ?gate 0) (eq ?gate ?dgate2))) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (delivery-period $?dp2&:(>= ?gt (nth$ 1 ?dp2))&:(<= ?gt (nth$ 2 ?dp2))) - (quantity-requested ?q-req-2) - (quantity-delivered $?q-del-2&:(< (order-q-del-team ?q-del-2 ?team) ?q-req-2))) - - (or - (test (> (- ?q-req-2 (order-q-del-team ?q-del-2 ?team)) (- ?q-req (order-q-del-team ?q-del ?team)))) - (test (and - (= (- ?q-req-2 (order-q-del-team ?q-del-2 ?team)) (- ?q-req (order-q-del-team ?q-del ?team))) - (< (nth$ 2 ?dp2) (nth$ 2 ?dp)))) - ) - )) - - ?sf <- (signal (type order-info)) - - => - (retract ?pf) - - ; Cause immediate sending of order info - (modify ?sf (time (create$ 0 0)) (count 0)) - - (bind ?q-del-idx (order-q-del-index ?team)) - (bind ?q-del-new (replace$ ?q-del ?q-del-idx ?q-del-idx (+ (nth$ ?q-del-idx ?q-del) 1))) - - (modify ?of (quantity-delivered ?q-del-new)) - - (foreach ?r ?ring-colors - (bind ?points 0) - (bind ?cc 0) - (do-for-fact ((?rs ring-spec)) (eq ?rs:color ?r) - (bind ?cc ?rs:req-bases) - (switch ?rs:req-bases - (case 0 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC0-STEP*)) - (case 1 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC1-STEP*)) - (case 2 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC2-STEP*)) - ) - ) - (assert (points (phase PRODUCTION) (game-time ?game-time) (team ?team) - (points ?points) - (reason (str-cat "Mounted CC" ?cc " ring " ?r-index " of CC" - ?cc " for order " ?id)))) - ) - (bind ?pre-cap-points 0) - (switch ?complexity - (case C1 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C1-PRECAP*)) - (case C2 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C2-PRECAP*)) - (case C3 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C3-PRECAP*)) - ) - (bind ?complexity-num (length$ ?ring-colors)) - (if (> ?complexity-num 0) then - (assert (points (game-time ?game-time) (points ?pre-cap-points) - (team ?team) (phase PRODUCTION) - (reason (str-cat "Mounted last ring for complexity " - ?complexity " order " ?id)))) - ) - - (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) - (points ?*PRODUCTION-POINTS-MOUNT-CAP*) - (reason (str-cat "Mounted cap for order " ?id)))) - - (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) - (points ?*PRODUCTION-POINTS-DELIVERY*) - (reason (str-cat "Delivered item for order " ?id)))) - -) (defrule order-delivered-by-color-late ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) @@ -306,15 +197,10 @@ (defrule order-delivered-wrong-delivgate ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) (order 0) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color)) + ?pf <- (product-delivered (game-time ?game-time) (team ?team) + (delivery-gate ?gate) (order ?id) (confirmed TRUE)) ; the actual order we are delivering - (order (id ?id) (active TRUE) (complexity ?complexity) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (quantity-requested ?q-req) (delivery-gate ?dgate&~?gate&:(neq ?gate 0))) - (not (order (id ?id2&~?id) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (delivery-gate ?gate))) + (order (id ?id) (active TRUE) (delivery-gate ?dgate&~?gate&:(neq ?gate 0))) => (retract ?pf) (printout warn "Delivered item for order " ?id " (wrong delivery gate, got " ?gate ", expected " ?dgate ")" crlf) @@ -327,17 +213,10 @@ (defrule order-delivered-wrong-too-soon ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) (order 0) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color)) + ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?id) + (confirmed TRUE)) ; the actual order we are delivering - (order (id ?id) (active TRUE) (complexity ?complexity) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (quantity-requested ?q-req) (delivery-gate ?gate|:(eq ?gate 0)) - (delivery-period $?dp&:(< ?gt (nth$ 1 ?dp)))) - (not (order (id ?id2&~?id) (active TRUE) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (delivery-gate ?gate) - (delivery-period $?dp&:(>= ?gt (nth$ 1 ?dp))))) + (order (id ?id) (active TRUE) (delivery-period $?dp&:(< ?gt (nth$ 1 ?dp)))) => (retract ?pf) (printout warn "Delivered item for order " ?id " (too soon, before time window)" crlf) @@ -350,12 +229,11 @@ (defrule order-delivered-wrong-too-many ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) (order 0) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color)) + ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?id) + (confirmed TRUE)) ; the actual order we are delivering - ?of <- (order (id ?id) (active TRUE) (complexity ?complexity) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (quantity-requested ?q-req) (delivery-gate ?gate|:(eq ?gate 0)) + ?of <- (order (id ?id) (active TRUE) + (quantity-requested ?q-req) (quantity-delivered $?q-del&:(>= (order-q-del-team ?q-del ?team) ?q-req))) => (retract ?pf) From c78efdd2624b4772de4e105bf91c302f1de155af Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 14:34:28 +0000 Subject: [PATCH 06/54] rcll: fix score computation when computing score based on order ID Depending on whether the delivered order was entered by color or by ID, the applied scoring rules differed. While scoring by color computed the correct score, scoring by ID computed the wrong score for the color complexity (e.g., 4 points instead of 20 points for CC2) and the pre-cap score (e.g., 0 points instead of 10 points for a C1). Fix the scoring by ID rules by applying the same rules as in the scoring by color case. --- src/games/rcll/orders.clp | 53 ++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 8f573e44b..3da5136af 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -74,38 +74,51 @@ (retract ?pf) (bind ?q-del-idx (order-q-del-index ?team)) (bind ?q-del-new (replace$ ?q-del ?q-del-idx ?q-del-idx (+ (nth$ ?q-del-idx ?q-del) 1))) - + (modify ?of (quantity-delivered ?q-del-new)) (if (< (nth$ ?q-del-idx ?q-del) ?q-req) then (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) - (points ?*PRODUCTION-POINTS-DELIVERY*) + (points ?*PRODUCTION-POINTS-DELIVERY*) (reason (str-cat "Delivered item for order " ?id)))) - (foreach ?r ?ring-colors - (do-for-fact ((?rs ring-spec)) (eq ?rs:color ?r) - (assert (points (game-time ?game-time) - (points (* ?rs:req-bases ?*PRODUCTION-POINTS-ADDITIONAL-BASE*)) - (team ?team) (phase PRODUCTION) - (reason (str-cat "Mounted ring of CC" ?rs:req-bases - " for order " ?id)))) - ) - ) - (bind ?complexity-num (length$ ?ring-colors)) - (if (> ?complexity-num 0) then - (assert (points (game-time ?game-time) ;(points (* ?complexity-num ?*PRODUCTION-POINTS-PER-RING*)) - (team ?team) (phase PRODUCTION) - (reason (str-cat "Mounted last ring for complexity " - ?complexity " order " ?id)))) - ) - + (foreach ?r ?ring-colors + (bind ?points 0) + (bind ?cc 0) + (do-for-fact ((?rs ring-spec)) (eq ?rs:color ?r) + (bind ?cc ?rs:req-bases) + (switch ?rs:req-bases + (case 0 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC0-STEP*)) + (case 1 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC1-STEP*)) + (case 2 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC2-STEP*)) + ) + ) + (assert (points (phase PRODUCTION) (game-time ?game-time) (team ?team) + (points ?points) + (reason (str-cat "Mounted CC" ?cc " ring of CC" ?cc + " for order " ?id)))) + ) + (bind ?pre-cap-points 0) + (switch ?complexity + (case C1 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C1-PRECAP*)) + (case C2 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C2-PRECAP*)) + (case C3 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C3-PRECAP*)) + ) + (bind ?complexity-num (length$ ?ring-colors)) + (if (> ?complexity-num 0) then + (assert (points (game-time ?game-time) (points ?pre-cap-points) + (team ?team) (phase PRODUCTION) + (reason (str-cat "Mounted last ring for complexity " + ?complexity " order " ?id)))) + ) + (assert (points (game-time ?game-time) (points ?*PRODUCTION-POINTS-MOUNT-CAP*) (team ?team) (phase PRODUCTION) (reason (str-cat "Mounted cap for order " ?id)))) else (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) - (points ?*PRODUCTION-POINTS-DELIVERY-WRONG*) + (points ?*PRODUCTION-POINTS-DELIVERY-WRONG*) (reason (str-cat "Delivered item for order " ?id)))) ) ) From dbbfd2aeb213241b2a81d0d9d141d2bf81a62ced Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 14:45:59 +0000 Subject: [PATCH 07/54] rcll: use delivery time for scoring, not current game time We store the time of the delivery when the DS goes into PROCESSED. This is the actual time of the delivery, not the time when we receive the delivery confirmation, which depends on the speed of the referee. Therefore, use that time to compute the score. Also rename the variable from ?game-time to ?delivery-time to make the distinction clearer. --- src/games/rcll/orders.clp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 3da5136af..fd2be3a73 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -61,24 +61,25 @@ (defrule order-delivered-correct - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) - (order ?id&~0) (confirmed TRUE)) + ?gf <- (gamestate (state RUNNING) (phase PRODUCTION)) + ?pf <- (product-delivered (game-time ?delivery-time) (team ?team) + (order ?id&~0) (delivery-gate ?gate) + (confirmed TRUE)) ; the actual order we are delivering ?of <- (order (id ?id) (active TRUE) (complexity ?complexity) - (delivery-gate ?dgate&:(or (eq ?gate 0) (eq ?gate ?dgate))) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (quantity-requested ?q-req) (quantity-delivered $?q-del) - (delivery-period $?dp&:(>= ?gt (nth$ 1 ?dp))&:(<= ?gt (nth$ 2 ?dp)))) + (delivery-gate ?dgate&:(or (eq ?gate 0) (eq ?gate ?dgate))) + (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) + (quantity-requested ?q-req) (quantity-delivered $?q-del) + (delivery-period $?dp &:(>= ?delivery-time (nth$ 1 ?dp)) + &:(<= ?delivery-time (nth$ 2 ?dp)))) => (retract ?pf) (bind ?q-del-idx (order-q-del-index ?team)) (bind ?q-del-new (replace$ ?q-del ?q-del-idx ?q-del-idx (+ (nth$ ?q-del-idx ?q-del) 1))) (modify ?of (quantity-delivered ?q-del-new)) - (if (< (nth$ ?q-del-idx ?q-del) ?q-req) - then - (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) + (if (< (nth$ ?q-del-idx ?q-del) ?q-req) then + (assert (points (game-time ?delivery-time) (team ?team) (phase PRODUCTION) (points ?*PRODUCTION-POINTS-DELIVERY*) (reason (str-cat "Delivered item for order " ?id)))) @@ -93,7 +94,7 @@ (case 2 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC2-STEP*)) ) ) - (assert (points (phase PRODUCTION) (game-time ?game-time) (team ?team) + (assert (points (phase PRODUCTION) (game-time ?delivery-time) (team ?team) (points ?points) (reason (str-cat "Mounted CC" ?cc " ring of CC" ?cc " for order " ?id)))) @@ -106,18 +107,18 @@ ) (bind ?complexity-num (length$ ?ring-colors)) (if (> ?complexity-num 0) then - (assert (points (game-time ?game-time) (points ?pre-cap-points) + (assert (points (game-time ?delivery-time) (points ?pre-cap-points) (team ?team) (phase PRODUCTION) (reason (str-cat "Mounted last ring for complexity " ?complexity " order " ?id)))) ) - (assert (points (game-time ?game-time) (points ?*PRODUCTION-POINTS-MOUNT-CAP*) + (assert (points (game-time ?delivery-time) (points ?*PRODUCTION-POINTS-MOUNT-CAP*) (team ?team) (phase PRODUCTION) (reason (str-cat "Mounted cap for order " ?id)))) else - (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) + (assert (points (game-time ?delivery-time) (team ?team) (phase PRODUCTION) (points ?*PRODUCTION-POINTS-DELIVERY-WRONG*) (reason (str-cat "Delivered item for order " ?id)))) ) From 02b99e286b4bfb8b13dc2fb0f9b40fff86123a99 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 15:15:00 +0000 Subject: [PATCH 08/54] rcll: add scoring for late delivery on ID confirmation So far we only computed the score for a late delivery if the delivery was confirmed by color. As we're getting rid of the color confirmation, also implement late delivery to ID confirmation. Also remove the code based on color confirmation. --- src/games/rcll/orders.clp | 107 +++++++++++--------------------------- 1 file changed, 29 insertions(+), 78 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index fd2be3a73..6643121d2 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -70,8 +70,7 @@ (delivery-gate ?dgate&:(or (eq ?gate 0) (eq ?gate ?dgate))) (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) (quantity-requested ?q-req) (quantity-delivered $?q-del) - (delivery-period $?dp &:(>= ?delivery-time (nth$ 1 ?dp)) - &:(<= ?delivery-time (nth$ 2 ?dp)))) + (delivery-period $?dp &:(>= ?delivery-time (nth$ 1 ?dp)))) => (retract ?pf) (bind ?q-del-idx (order-q-del-index ?team)) @@ -79,10 +78,32 @@ (modify ?of (quantity-delivered ?q-del-new)) (if (< (nth$ ?q-del-idx ?q-del) ?q-req) then - (assert (points (game-time ?delivery-time) (team ?team) (phase PRODUCTION) - (points ?*PRODUCTION-POINTS-DELIVERY*) - (reason (str-cat "Delivered item for order " ?id)))) + ; Delivery points + (if (<= ?delivery-time (nth$ 2 ?dp)) then + (assert (points (game-time ?delivery-time) (team ?team) (phase PRODUCTION) + (points ?*PRODUCTION-POINTS-DELIVERY*) + (reason (str-cat "Delivered item for order " ?id)))) + else + (if (< (- ?delivery-time (nth$ 2 ?dp)) + ?*PRODUCTION-DELIVER-MAX-LATENESS-TIME*) + then + ; 15 - floor(T_d - T_e) * 1.5 + 5 + (bind ?points (+ (- 15 (* (floor (- ?delivery-time (nth$ 2 ?dp))) 1.5)) 5)) + (assert (points (game-time ?delivery-time) (points (integer ?points)) + (team ?team) (phase PRODUCTION) + (reason (str-cat "Delivered item for order " ?id + " (late delivery grace time)")))) + else + (assert (points (game-time ?delivery-time) + (points ?*PRODUCTION-POINTS-DELIVERY-TOO-LATE*) + (team ?team) (phase PRODUCTION) + (reason (str-cat "Delivered item for order " ?id + " (too late delivery)")))) + ) + ) + + ; Production points for ring color complexities (foreach ?r ?ring-colors (bind ?points 0) (bind ?cc 0) @@ -99,6 +120,8 @@ (reason (str-cat "Mounted CC" ?cc " ring of CC" ?cc " for order " ?id)))) ) + + ; Production points for mounting the last ring (pre-cap points) (bind ?pre-cap-points 0) (switch ?complexity (case C1 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C1-PRECAP*)) @@ -113,6 +136,7 @@ ?complexity " order " ?id)))) ) + ; Production points for mounting the cap (assert (points (game-time ?delivery-time) (points ?*PRODUCTION-POINTS-MOUNT-CAP*) (team ?team) (phase PRODUCTION) (reason (str-cat "Mounted cap for order " ?id)))) @@ -136,79 +160,6 @@ ?order crlf)))) ) - -(defrule order-delivered-by-color-late - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) - ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) (order 0) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color)) - ; the actual order we are delivering - ?of <- (order (id ?id) (active TRUE) (complexity ?complexity) - (delivery-gate ?dgate&:(or (eq ?gate 0) (eq ?gate ?dgate))) - (base-color ?base-color) (ring-colors $?ring-colors) (cap-color ?cap-color) - (quantity-requested ?q-req) - (quantity-delivered $?q-del&:(< (order-q-del-team ?q-del ?team) ?q-req)) - (delivery-period $?dp&:(> ?gt (nth$ 2 ?dp)))) - - ?sf <- (signal (type order-info)) - => - (retract ?pf) - - ; Cause immediate sending of order info - (modify ?sf (time (create$ 0 0)) (count 0)) - - (bind ?q-del-idx (order-q-del-index ?team)) - (bind ?q-del-new (replace$ ?q-del ?q-del-idx ?q-del-idx (+ (nth$ ?q-del-idx ?q-del) 1))) - (modify ?of (quantity-delivered ?q-del-new)) - - (foreach ?r ?ring-colors - (bind ?points 0) - (bind ?cc 0) - (do-for-fact ((?rs ring-spec)) (eq ?rs:color ?r) - (bind ?cc ?rs:req-bases) - (switch ?rs:req-bases - (case 0 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC0-STEP*)) - (case 1 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC1-STEP*)) - (case 2 then (bind ?points ?*PRODUCTION-POINTS-FINISH-CC2-STEP*)) - ) - ) - (assert (points (phase PRODUCTION) (game-time ?game-time) (team ?team) - (points ?points) - (reason (str-cat "Mounted CC" ?cc " ring of CC" ?cc " for order " ?id)))) - ) - (bind ?pre-cap-points 0) - (switch ?complexity - (case C1 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C1-PRECAP*)) - (case C2 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C2-PRECAP*)) - (case C3 then (bind ?pre-cap-points ?*PRODUCTION-POINTS-FINISH-C3-PRECAP*)) - ) - (bind ?complexity-num (length$ ?ring-colors)) - (if (> ?complexity-num 0) then - (assert (points (game-time ?game-time) (points ?pre-cap-points) - (team ?team) (phase PRODUCTION) - (reason (str-cat "Mounted last ring for complexity " - ?complexity " order " ?id)))) - ) - - (assert (points (game-time ?game-time) (team ?team) (phase PRODUCTION) - (points ?*PRODUCTION-POINTS-MOUNT-CAP*) - (reason (str-cat "Mounted cap for order " ?id)))) - - (if (< (- ?gt (nth$ 2 ?dp)) ?*PRODUCTION-DELIVER-MAX-LATENESS-TIME*) - then - ; 15 - floor(T_d - T_e) * 1.5 + 5 - (bind ?points (+ (- 15 (* (floor (- ?game-time (nth$ 2 ?dp))) 1.5)) 5)) - (assert (points (game-time ?game-time) (points (integer ?points)) - (team ?team) (phase PRODUCTION) - (reason (str-cat "Delivered item for order " ?id - " (late delivery grace time)")))) - else - (assert (points (game-time ?game-time) (points ?*PRODUCTION-POINTS-DELIVERY-TOO-LATE*) - (team ?team) (phase PRODUCTION) - (reason (str-cat "Delivered item for order " ?id - " (too late delivery)")))) - ) -) - (defrule order-delivered-wrong-delivgate ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) From 3025a4619b691018186f267b7093b98ef190680c Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 15:21:06 +0000 Subject: [PATCH 09/54] rcll: also process OrderDelivered message in post-game The message will be sent by manual confirmation by the referee. This may also happen after the game has already ended. Therefore, do not constrain processing of the message on the game phase. --- src/games/rcll/orders.clp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 6643121d2..613c5583c 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -40,7 +40,6 @@ ) (defrule order-recv-SetOrderDelivered - (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) ?pf <- (protobuf-msg (type "llsf_msgs.SetOrderDelivered") (ptr ?p) (rcvd-via STREAM)) => (if (not (do-for-fact From 90376480f40195ffacc09cffc45e2efa1f3bbda9 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 17:00:07 +0000 Subject: [PATCH 10/54] shell: do not show deliver menu by color, directly go to menu by ID --- src/shell/menus.cpp | 196 -------------------------------------------- src/shell/menus.h | 33 -------- src/shell/shell.cpp | 21 ++--- 3 files changed, 6 insertions(+), 244 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 14501a007..096f3d634 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -690,200 +690,4 @@ OrderDeliverMenu::operator bool() const } -OrderByColorDeliverMenu::OrderByColorDeliverMenu - (NCursesWindow *parent, llsf_msgs::Team team, - std::shared_ptr oinfo, - std::shared_ptr gstate) - : Menu(det_lines(team, oinfo) + 2 + 2, 18 + 2, - (parent->lines() - (det_lines(team, oinfo) + 2))/2, - (parent->cols() - 19)/2), - oinfo_(oinfo), team_(team) -{ - product_selected_ = false; - product_idx_ = 0; - wants_specific_ = false; - int n_items = det_lines(team, oinfo); - items_.resize(n_items); - int ni = 0; - NCursesMenuItem **mitems = new NCursesMenuItem*[3 + n_items]; - - std::list orders; - - for (int i = 0; i < oinfo->orders_size(); ++i) { - const llsf_msgs::Order &o = oinfo->orders(i); - - std::string os = product_spec_to_string(o); - if (std::find(orders.begin(), orders.end(), os) == orders.end()) { - orders.push_back(os); - - std::string s = boost::str(boost::format("%2s ") - % llsf_msgs::Order::Complexity_Name(o.complexity())); - std::vector ring_colors(o.ring_colors_size()); - for (int i = 0; i < o.ring_colors_size(); ++i) ring_colors[i] = o.ring_colors(i); - items_[ni++] = std::make_tuple(o.base_color(), ring_colors, o.cap_color(), s); - } - } - - std::sort(items_.begin(), items_.end()); - - for (int i = 0; i < ni; ++i) { - SignalItem *item = new SignalItem(std::get<3>(items_[i])); - item->signal().connect(boost::bind(&OrderByColorDeliverMenu::product_selected, - this, i)); - mitems[i] = item; - } - - s_specific_ = "==> Specific"; - SignalItem *item_spec = new SignalItem(s_specific_); - item_spec->signal().connect(boost::bind(&OrderByColorDeliverMenu::set_wants_specific, this)); - mitems[ni] = item_spec; - - s_cancel_ = "** CANCEL **"; - mitems[ni+1] = new SignalItem(s_cancel_); - mitems[ni+2] = new NCursesMenuItem(); - - set_mark(""); - set_format(ni+2, 1); - InitMenu(mitems, true, true); -} - -void -OrderByColorDeliverMenu::product_selected(int i) -{ - product_selected_ = true; - product_idx_ = i; -} - -void -OrderByColorDeliverMenu::set_wants_specific() -{ - wants_specific_ = true; -} - - -bool -OrderByColorDeliverMenu::wants_specific() -{ - return wants_specific_; -} - -llsf_msgs::BaseColor -OrderByColorDeliverMenu::base_color() -{ - return std::get<0>(items_[product_idx_]); -} - -std::vector -OrderByColorDeliverMenu::ring_colors() -{ - return std::get<1>(items_[product_idx_]); -} - -llsf_msgs::CapColor -OrderByColorDeliverMenu::cap_color() -{ - return std::get<2>(items_[product_idx_]); -} - -void -OrderByColorDeliverMenu::On_Menu_Init() -{ - bkgd(' '|COLOR_PAIR(COLOR_DEFAULT)); - - if (team_ == llsf_msgs::CYAN) { - attron(' '|COLOR_PAIR(COLOR_CYAN_ON_BACK)); - } else { - attron(' '|COLOR_PAIR(COLOR_MAGENTA_ON_BACK)); - } - box(); - - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)|A_BOLD); - addstr(0, (width() - 8) / 2, " Orders "); - attroff(A_BOLD); - - for (size_t i = 0; i < items_.size(); ++i) { - switch (std::get<0>(items_[i])) { - case llsf_msgs::BASE_RED: - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_RED)); break; - case llsf_msgs::BASE_SILVER: - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; - case llsf_msgs::BASE_BLACK: - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; - } - addstr(i+1, 14, " "); - - for (size_t j = 0; j < std::get<1>(items_[i]).size(); ++j) { - switch (std::get<1>(items_[i]).at(j)) { - case llsf_msgs::RING_BLUE: - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLUE)); break; - case llsf_msgs::RING_GREEN: - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_GREEN)); break; - case llsf_msgs::RING_ORANGE: - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_ORANGE)); break; - case llsf_msgs::RING_YELLOW: - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_YELLOW)); break; - } - addstr(i+1, 15+j, " "); - } - - for (int j = std::get<1>(items_[i]).size(); j < 4; ++j) { - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); - addstr(i+1, 15+j, " "); - } - - switch (std::get<2>(items_[i])) { - case llsf_msgs::CAP_BLACK: - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; - case llsf_msgs::CAP_GREY: - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; - } - addstr(i+1, 18, " "); - - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)); - } - - refresh(); -} - - -std::string -OrderByColorDeliverMenu::product_spec_to_string(const llsf_msgs::Order &o) -{ - std::string rv = llsf_msgs::BaseColor_Name(o.base_color()) + "-"; - - for (int i = 0; i < o.ring_colors_size(); ++i) { - if (i > 0) rv += "|"; - rv += llsf_msgs::RingColor_Name(o.ring_colors(i)); - } - - rv += "-" + llsf_msgs::CapColor_Name(o.cap_color()); - return rv; -} - -int -OrderByColorDeliverMenu::det_lines(llsf_msgs::Team team, - std::shared_ptr &oinfo) -{ - if (oinfo) { - int num_products = 0; - std::list orders; - for (int i = 0; i < oinfo->orders_size(); ++i) { - std::string os = product_spec_to_string(oinfo->orders(i)); - if (std::find(orders.begin(), orders.end(), os) == orders.end()) { - orders.push_back(os); - num_products += 1; - } - } - return num_products; - } else { - return 0; - } -} - -OrderByColorDeliverMenu::operator bool() const -{ - return product_selected_; -} - - } // end of namespace llsfrb diff --git a/src/shell/menus.h b/src/shell/menus.h index ecad631a0..5520de2fb 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -225,39 +225,6 @@ class OrderDeliverMenu : public Menu std::vector items_; }; -class OrderByColorDeliverMenu : public Menu -{ - public: - OrderByColorDeliverMenu(NCursesWindow *parent, llsf_msgs::Team team, - std::shared_ptr oinfo, - std::shared_ptr gstate); - - llsf_msgs::BaseColor base_color(); - std::vector ring_colors(); - llsf_msgs::CapColor cap_color(); - bool wants_specific(); - operator bool() const; - - private: - typedef std::tuple, llsf_msgs::CapColor, std::string> ItemTuple; - - virtual void On_Menu_Init(); - int det_lines(llsf_msgs::Team team, std::shared_ptr &oinfo); - std::string product_spec_to_string(const llsf_msgs::Order &o); - void product_selected(int i); - void set_wants_specific(); - - private: - std::shared_ptr oinfo_; - llsf_msgs::Team team_; - bool wants_specific_; - bool product_selected_; - int product_idx_; - std::string s_specific_; - std::string s_cancel_; - std::vector items_; -}; - } // end of namespace llsfrb diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 02627c13e..517e0c56e 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -326,21 +326,12 @@ LLSFRefBoxShell::handle_keyboard(const boost::system::error_code& error) TeamColorSelectMenu tcsm(panel_); tcsm(); if (tcsm) { - OrderByColorDeliverMenu odm(panel_, tcsm.get_team_color(), - last_orderinfo_, last_game_state_); - odm(); - if (odm) { - send_set_order_delivered(tcsm.get_team_color(), - odm.base_color(), odm.ring_colors(), odm.cap_color()); - } else if (odm.wants_specific()) { - io_service_.dispatch(boost::bind(&LLSFRefBoxShell::refresh, this)); - OrderDeliverMenu odm_spec(panel_, tcsm.get_team_color(), - last_orderinfo_, last_game_state_); - odm_spec(); - if (odm_spec) { - send_set_order_delivered(tcsm.get_team_color(), odm_spec.order()); - } - } + OrderDeliverMenu odm(panel_, tcsm.get_team_color(), + last_orderinfo_, last_game_state_); + odm(); + if (odm) { + send_set_order_delivered(tcsm.get_team_color(), odm.order()); + } } io_service_.dispatch(boost::bind(&LLSFRefBoxShell::refresh, this)); } From 38105b2d15b44c0390ddf4312f5b36c5f1340c7e Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 17:04:43 +0000 Subject: [PATCH 11/54] rcll: also send the order_id in DS machine state message --- src/games/rcll/net.clp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/games/rcll/net.clp b/src/games/rcll/net.clp index 3d9c813f7..7570e7d5a 100644 --- a/src/games/rcll/net.clp +++ b/src/games/rcll/net.clp @@ -440,6 +440,7 @@ (case DS then (bind ?pm (pb-create "llsf_msgs.PrepareInstructionDS")) (pb-set-field ?pm "gate" (fact-slot-value ?mf ds-gate)) + (pb-set-field ?pm "order_id" (fact-slot-value ?mf ds-order)) (pb-set-field ?m "instruction_ds" ?pm) ) (case SS then From 8147704e6460089a584ee5a70632970432fc2f04 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 17:06:28 +0000 Subject: [PATCH 12/54] rcll-prepare-machine: also send order ID in prepare msg for DS --- src/tools/rcll-prepare-machine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/rcll-prepare-machine.cpp b/src/tools/rcll-prepare-machine.cpp index ffff8ddcf..5e5e490a0 100644 --- a/src/tools/rcll-prepare-machine.cpp +++ b/src/tools/rcll-prepare-machine.cpp @@ -58,6 +58,7 @@ std::string machine_type_; llsf_msgs::MachineSide bs_side_; llsf_msgs::BaseColor bs_color_; int ds_gate_; +int ds_order_id_; llsf_msgs::SSOp ss_op_; int ss_slot_x_; int ss_slot_y_; @@ -171,6 +172,7 @@ handle_message(boost::asio::ip::udp::endpoint &sender, } else if (machine_type_ == "DS") { llsf_msgs::PrepareInstructionDS *prep_ds = prep.mutable_instruction_ds(); prep_ds->set_gate(ds_gate_); + prep_ds->set_order_id(ds_order_id_); } else if (machine_type_ == "SS") { llsf_msgs::PrepareInstructionSS *prep_ss = prep.mutable_instruction_ss(); @@ -200,7 +202,7 @@ usage(const char *progname) "\n" "instructions are specific for the machine type:\n" "BS: (INPUT|OUTPUT) (BASE_RED|BASE_BLACK|BASE_SILVER)\n" - "DS: \n" + "DS: \n" "SS: (RETRIEVE|STORE) \n" "RS: (RING_BLUE|RING_GREEN|RING_ORANGE|RING_YELLOW)\n" "CS: (RETRIEVE_CAP|MOUNT_CAP)\n", @@ -236,6 +238,7 @@ main(int argc, char **argv) } } else if (machine_type_ == "DS") { ds_gate_ = argp.parse_item_int(2); + ds_order_id_ = argp.parse_item_int(3); } else if (machine_type_ == "SS") { if (argp.num_items() < 6) { printf("SS machine requires operation and x, y, z arguments %zu\n", argp.num_items()); From bf61404115dbdbeab6eb6f91e0e043ff47b00850 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Mon, 21 Jan 2019 17:58:47 +0000 Subject: [PATCH 13/54] rcll: send delivery msg if a new unconfirmed delivery occurred The message is sent to the shell so it can be confirmed by a referee. --- src/games/rcll/net.clp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/games/rcll/net.clp b/src/games/rcll/net.clp index 7570e7d5a..343d10fd5 100644 --- a/src/games/rcll/net.clp +++ b/src/games/rcll/net.clp @@ -197,6 +197,28 @@ (pb-destroy ?attmsg) ) +(defrule send-delivery-msg + ?pd <- (product-delivered (id ?id) (team ?team) (order ?order) + (game-time ?time) (confirmed FALSE) + (delivery-gate ?gate)) + => + (bind ?msg (pb-create "llsf_msgs.UnconfirmedDelivery")) + (pb-set-field ?msg "id" ?id) + (pb-set-field ?msg "team_color" ?team) + (pb-set-field ?msg "order_id" ?order) + (pb-set-field ?msg "gate" ?gate) + (bind ?delivery-time (pb-field-value ?msg "delivery_time")) + (if (eq (type ?delivery-time) EXTERNAL-ADDRESS) then + (bind ?gt (time-from-sec ?time)) + (pb-set-field ?delivery-time "sec" (nth$ 1 ?gt)) + (pb-set-field ?delivery-time "nsec" (integer (* (nth$ 2 ?gt) 1000))) + (pb-set-field ?msg "delivery_time" ?delivery-time) ; destroys ?delivery-time! + ) + (do-for-all-facts ((?client network-client)) (not ?client:is-slave) + (pb-send ?client:id ?msg)) + (pb-destroy ?msg) +) + (defrule net-recv-SetGameState ?sf <- (gamestate (state ?state)) ?mf <- (protobuf-msg (type "llsf_msgs.SetGameState") (ptr ?p) (rcvd-via STREAM)) From 19a461e7271a869414286b06f38cb7ac1fe1523b Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 13:23:19 +0000 Subject: [PATCH 14/54] rcll: add utils function to generate a unique uint ID This can be used for fields that need to be unique (e.g., an ID) but that should be an integer, not a symbol (e.g., for storing it as a uint in a protobuf message). --- src/games/rcll/utils.clp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/games/rcll/utils.clp b/src/games/rcll/utils.clp index 6216e20c2..a45a5c866 100644 --- a/src/games/rcll/utils.clp +++ b/src/games/rcll/utils.clp @@ -146,6 +146,12 @@ (return ?rv) ) +(deffunction gen-int-id () + "Generate a unique uint that can be used as an ID." + (bind ?id-string (str-cat (gensym*))) + (return (string-to-field (sub-string 4 (length$ ?id-string) ?id-string))) +) + (deffunction ceil (?f) (bind ?rf (round ?f)) From 7a7c63e1e88a3e12128a1e66ecfcfd86b3c26470 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 13:29:10 +0000 Subject: [PATCH 15/54] rcll: add ID slot to product-delivered deftemplate We need an ID so we can confirm the right delivery even if there were multiple deliveries for the same order. --- src/games/rcll/facts.clp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/games/rcll/facts.clp b/src/games/rcll/facts.clp index 390eb8ea1..99aa44116 100644 --- a/src/games/rcll/facts.clp +++ b/src/games/rcll/facts.clp @@ -217,6 +217,7 @@ ) (deftemplate product-delivered + (slot id (default-dynamic (gen-int-id))) (slot game-time (type FLOAT)) (slot order (type INTEGER) (default 0)) (slot team (type SYMBOL) (allowed-values nil CYAN MAGENTA)) From 155c6fe78d4c79612a39430ee8a9e745adb93722 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 13:32:17 +0000 Subject: [PATCH 16/54] msgs: add message for an unconfirmed delivery The message informs the refbox shell that there has been a new, unconfirmed delivery. The referee can then confirm the correct delivery in the shell. --- src/msgs/OrderInfo.proto | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/msgs/OrderInfo.proto b/src/msgs/OrderInfo.proto index b9f5ba71d..173f7b6d7 100644 --- a/src/msgs/OrderInfo.proto +++ b/src/msgs/OrderInfo.proto @@ -39,6 +39,7 @@ syntax = "proto2"; package llsf_msgs; import "Team.proto"; +import "Time.proto"; import "ProductColor.proto"; option java_package = "org.robocup_logistics.llsf_msgs"; @@ -92,6 +93,19 @@ message OrderInfo { repeated Order orders = 1; } +message UnconfirmedDelivery { + enum CompType { + COMP_ID = 2000; + MSG_TYPE = 45; + } + + required uint32 id = 1; + required Team team_color = 2; + required uint32 order_id = 3; + required uint32 gate = 4; + required Time delivery_time = 5; +} + message SetOrderDelivered { enum CompType { From 6f306c4b0606b534a38f3efbb6163eadbf096168 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 13:36:37 +0000 Subject: [PATCH 17/54] shell: remove unused func to send info about delivery by color We no longer confirm deliveries by color but only by order. Remove the function that created and sent the message. --- src/shell/shell.cpp | 26 -------------------------- src/shell/shell.h | 3 --- 2 files changed, 29 deletions(-) diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 517e0c56e..5826e06ab 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -526,32 +526,6 @@ LLSFRefBoxShell::send_set_order_delivered(llsf_msgs::Team team, const llsf_msgs: */ } -void -LLSFRefBoxShell::send_set_order_delivered(llsf_msgs::Team team, llsf_msgs::BaseColor base_color, - std::vector ring_colors, - llsf_msgs::CapColor cap_color) -{ - llsf_msgs::SetOrderDeliveredByColor od; - od.set_team_color(team); - od.set_base_color(base_color); - for (const auto &c : ring_colors) od.add_ring_colors(c); - od.set_cap_color(cap_color); - std::string ring_colors_s; - for (size_t i = 0; i < ring_colors.size(); ++i) { - if (i > 0) ring_colors_s += "|"; - ring_colors_s += llsf_msgs::RingColor_Name(ring_colors[i]).c_str(); - } - logf("Sending completed order for team %s (base: %s, rings: %s, cap: %s)", - llsf_msgs::Team_Name(team).c_str(), - llsf_msgs::BaseColor_Name(base_color).c_str(), ring_colors_s.c_str(), - llsf_msgs::CapColor_Name(cap_color).c_str()); - try { - client->send(od); - } catch (std::runtime_error &e) { - logf("Sending SetOrderDelivered failed: %s", e.what()); - } -} - void LLSFRefBoxShell::client_connected() { diff --git a/src/shell/shell.h b/src/shell/shell.h index 097ab8ab0..4738cf359 100644 --- a/src/shell/shell.h +++ b/src/shell/shell.h @@ -119,9 +119,6 @@ class LLSFRefBoxShell void send_robot_maintenance(llsf_msgs::Team team, unsigned int robot_number, bool maintenance); void send_set_order_delivered(llsf_msgs::Team team, const llsf_msgs::Order &order); - void send_set_order_delivered(llsf_msgs::Team team, llsf_msgs::BaseColor base_color, - std::vector ring_colors, - llsf_msgs::CapColor cap_color); void log(llsf_log_msgs::LogMessage::LogLevel log_level, long int ts_sec, long int ts_nsec, From 90d273de86798ebafa7d37813fb5c2d1ed97a538 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 13:38:54 +0000 Subject: [PATCH 18/54] msgs: remove unused SetOrderDeliveredByColor message We no longer confirm deliveries by color but only by order. Remove the message that would confirm a delivery by color. --- src/msgs/OrderInfo.proto | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/msgs/OrderInfo.proto b/src/msgs/OrderInfo.proto index 173f7b6d7..cbb30c9f0 100644 --- a/src/msgs/OrderInfo.proto +++ b/src/msgs/OrderInfo.proto @@ -116,19 +116,3 @@ message SetOrderDelivered { required Team team_color = 1; required uint32 order_id = 2; } - - -message SetOrderDeliveredByColor { - enum CompType { - COMP_ID = 2000; - MSG_TYPE = 44; - } - - required Team team_color = 1; - - /** Colors of delivered product. Zero, - * or more rings orderd from bottom to top */ - required BaseColor base_color = 3; - repeated RingColor ring_colors = 4; - required CapColor cap_color = 5; -} From f7e8f54f5424975d8605548867bdab66ffffa6e7 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 13:41:17 +0000 Subject: [PATCH 19/54] msgs: replace SetOrderDelivered msg by ConfirmDelivery msg The new message confirms a delivery by the ID of the delivery, not by order ID. It also contains a new field 'correct'. If it is set to true, then the delivered product was as specified in the requeste order. If it is set to false, then the wrong product was delivered. The message format has changed completely, so rename the message and also change the MSG_TYPE. --- src/msgs/OrderInfo.proto | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/msgs/OrderInfo.proto b/src/msgs/OrderInfo.proto index cbb30c9f0..e8804e33c 100644 --- a/src/msgs/OrderInfo.proto +++ b/src/msgs/OrderInfo.proto @@ -107,12 +107,12 @@ message UnconfirmedDelivery { } -message SetOrderDelivered { +message ConfirmDelivery { enum CompType { COMP_ID = 2000; - MSG_TYPE = 43; + MSG_TYPE = 46; } - required Team team_color = 1; - required uint32 order_id = 2; + required uint32 delivery_id = 1; + required bool correct = 2; } From cdb9256107a8a5f12a651cee538b1143b07a2fad Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 22 Jan 2019 14:11:27 +0000 Subject: [PATCH 20/54] shell: store UnconfirmedDelivery messages received from the refbox --- src/shell/shell.cpp | 17 +++++++++++++++++ src/shell/shell.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 5826e06ab..4ab55df3f 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -821,6 +821,22 @@ LLSFRefBoxShell::client_msg(uint16_t comp_id, uint16_t msg_type, } } + std::shared_ptr delivery; + if ((delivery = std::dynamic_pointer_cast(msg))) { + bool duplicate = false; + for (auto && existing_delivery : unconfirmed_deliveries_) { + if (existing_delivery->id() == delivery->id()) { + duplicate = true; + break; + } + } + if (!duplicate) { + unconfirmed_deliveries_.push_back(delivery); + logf("New unconfirmed delivery by %s for order %u", + llsf_msgs::Team_Name(delivery->team_color()).c_str(), + delivery->order_id()); + } + } std::shared_ptr lm; if ((lm = std::dynamic_pointer_cast(msg))) { @@ -1153,6 +1169,7 @@ LLSFRefBoxShell::run() message_register.add_message_type(); message_register.add_message_type(); message_register.add_message_type(); + message_register.add_message_type(); client->signal_connected().connect( boost::bind(&LLSFRefBoxShell::dispatch_client_connected, this)); diff --git a/src/shell/shell.h b/src/shell/shell.h index 4738cf359..4637032b4 100644 --- a/src/shell/shell.h +++ b/src/shell/shell.h @@ -167,6 +167,8 @@ class LLSFRefBoxShell std::vector robots_; std::map machines_; std::vector orders_; + std::vector> + unconfirmed_deliveries_; boost::asio::io_service io_service_; boost::asio::deadline_timer timer_; From 881bdd9fa16420dba825a80e3dfffb82d2ee6521 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Wed, 23 Jan 2019 17:29:19 +0000 Subject: [PATCH 21/54] rcll: move gen-int-id function into facts The function is used by the product-delivered deftemplate and must be defined before the deftemplate. As we must load facts.clp before utils.clp, the function must be defined in facts.clp, not in utils.clp. --- src/games/rcll/facts.clp | 6 ++++++ src/games/rcll/utils.clp | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/games/rcll/facts.clp b/src/games/rcll/facts.clp index 99aa44116..a4d852ae6 100644 --- a/src/games/rcll/facts.clp +++ b/src/games/rcll/facts.clp @@ -216,6 +216,12 @@ (multislot period (type INTEGER) (cardinality 2 2)) ) +(deffunction gen-int-id () + "Generate a unique uint that can be used as an ID." + (bind ?id-string (str-cat (gensym*))) + (return (string-to-field (sub-string 4 (length$ ?id-string) ?id-string))) +) + (deftemplate product-delivered (slot id (default-dynamic (gen-int-id))) (slot game-time (type FLOAT)) diff --git a/src/games/rcll/utils.clp b/src/games/rcll/utils.clp index a45a5c866..edb4f7e39 100644 --- a/src/games/rcll/utils.clp +++ b/src/games/rcll/utils.clp @@ -146,13 +146,6 @@ (return ?rv) ) -(deffunction gen-int-id () - "Generate a unique uint that can be used as an ID." - (bind ?id-string (str-cat (gensym*))) - (return (string-to-field (sub-string 4 (length$ ?id-string) ?id-string))) -) - - (deffunction ceil (?f) (bind ?rf (round ?f)) (return (if (>= (- ?rf ?f) 0) then ?rf else (+ ?rf 1))) From 95f9811a2558859da88948799ac6c92693ef7169 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Wed, 23 Jan 2019 17:30:56 +0000 Subject: [PATCH 22/54] rcll: fix slot type for slot id of product-delivered deftemplate --- src/games/rcll/facts.clp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/games/rcll/facts.clp b/src/games/rcll/facts.clp index a4d852ae6..3ca52faad 100644 --- a/src/games/rcll/facts.clp +++ b/src/games/rcll/facts.clp @@ -223,7 +223,7 @@ ) (deftemplate product-delivered - (slot id (default-dynamic (gen-int-id))) + (slot id (type INTEGER) (default-dynamic (gen-int-id))) (slot game-time (type FLOAT)) (slot order (type INTEGER) (default 0)) (slot team (type SYMBOL) (allowed-values nil CYAN MAGENTA)) From 176de0cca95c0c83d0d94333a29efa4c6983024c Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Wed, 23 Jan 2019 17:50:15 +0000 Subject: [PATCH 23/54] rcll: expect a ConfirmDelivery message for delivery confirmation --- src/games/rcll/orders.clp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 613c5583c..59169c246 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -40,13 +40,12 @@ ) (defrule order-recv-SetOrderDelivered - ?pf <- (protobuf-msg (type "llsf_msgs.SetOrderDelivered") (ptr ?p) (rcvd-via STREAM)) + ?pf <- (protobuf-msg (type "llsf_msgs.ConfirmDelivery") (ptr ?p) (rcvd-via STREAM)) => (if (not (do-for-fact ((?pd product-delivered)) - (and (eq ?pd:order (pb-field-value ?p "order_id")) - (eq ?pd:team (sym-cat (pb-field-value ?p "team_color")))) - (eq ?pd:confirmed FALSE) + (and (eq ?pd:id (pb-field-value ?p "delivery_id")) + (eq ?pd:confirmed FALSE)) (printout t "Confirmed delivery of order " ?pd:order " by team " ?pd:team crlf) (modify ?pd (confirmed TRUE)))) From 13cda2ff58642955bc2f0d0b53d025a2354a1b4e Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 10:47:37 +0000 Subject: [PATCH 24/54] shell: only show unconfirmed deliveries in OrderDeliverMenu This replaces a good part of the menu. We now only show deliveries that have not been confirmed yet. We also no longer distinguish by order, but by delivery ID. This doesn't show the correct order configuration (i.e., the base, ring, and cap colors) yet. It's also not yet possible to report an incorrect delivery, a delivey is always assumed to be correct if confirmed. --- src/shell/menus.cpp | 88 ++++++++++++++++++++++----------------------- src/shell/menus.h | 13 ++++--- src/shell/shell.cpp | 35 +++++++----------- src/shell/shell.h | 2 +- 4 files changed, 65 insertions(+), 73 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 096f3d634..213c8ccbc 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -539,34 +539,44 @@ RobotMaintenanceMenu::det_cols(std::shared_ptr &rinfo) OrderDeliverMenu::OrderDeliverMenu (NCursesWindow *parent, llsf_msgs::Team team, + std::vector> deliveries, std::shared_ptr oinfo, std::shared_ptr gstate) - : Menu(det_lines(team, oinfo) + 1 + 2, 25 + 2, - (parent->lines() - (det_lines(team, oinfo) + 1))/2, + : Menu(det_lines(team, deliveries) + 1 + 2, 25 + 2, + (parent->lines() - (det_lines(team, deliveries) + 1))/2, (parent->cols() - 26)/2), oinfo_(oinfo), team_(team) { - order_selected_ = false; - int n_items = det_lines(team, oinfo); + delivery_selected_ = false; + int n_items = det_lines(team, deliveries); items_.resize(n_items); int ni = 0; NCursesMenuItem **mitems = new NCursesMenuItem*[2 + n_items]; - for (int i = 0; i < oinfo->orders_size(); ++i) { - const llsf_msgs::Order &o = oinfo->orders(i); - - bool active = (gstate->game_time().sec() >= o.delivery_period_begin() && - gstate->game_time().sec() <= o.delivery_period_end()); - - std::string s = boost::str(boost::format("%s %2u: %u x %2s") - % (active ? "*" : " ") % o.id() % o.quantity_requested() - % llsf_msgs::Order::Complexity_Name(o.complexity())); - items_[ni++] = std::make_pair(i, s); + for (size_t i = 0; i < deliveries.size(); i++) { + std::shared_ptr delivery = deliveries[i]; + int min = delivery->delivery_time().sec() / 60; + int sec = delivery->delivery_time().sec() - min * 60; + std::string s; + for (int j = 0; j < oinfo->orders_size(); ++j) { + const llsf_msgs::Order &o = oinfo->orders(j); + if (o.id() == delivery->order_id()) { + s = boost::str(boost::format("%2u: %2s %2u:%2u") + % o.id() + % llsf_msgs::Order::Complexity_Name(o.complexity()) + % min % sec); + break; + } + } + if (s.empty()) { + s = boost::str(boost::format("%2u: ?? ??:??") % delivery->order_id()); + } + items_[ni++] = std::make_pair(delivery->order_id(), s); } std::sort(items_.begin(), items_.end()); for (int i = 0; i < ni; ++i) { SignalItem *item = new SignalItem(items_[i].second); - item->signal().connect(boost::bind(&OrderDeliverMenu::order_selected, + item->signal().connect(boost::bind(&OrderDeliverMenu::delivery_selected, this, items_[i].first)); mitems[i] = item; } @@ -580,16 +590,16 @@ OrderDeliverMenu::OrderDeliverMenu } void -OrderDeliverMenu::order_selected(int i) +OrderDeliverMenu::delivery_selected(int i) { - order_selected_ = true; - order_idx_ = i; + delivery_selected_ = true; + delivery_idx_ = i; } -const llsf_msgs::Order & -OrderDeliverMenu::order() +int +OrderDeliverMenu::delivery() const { - return oinfo_->orders(order_idx_); + return delivery_idx_; } void @@ -616,18 +626,6 @@ OrderDeliverMenu::On_Menu_Init() } else { attron(' '|COLOR_PAIR(COLOR_CYAN_ON_BACK)); } - printw(i+1, 14, "%u", o.quantity_delivered_cyan()); - - attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)); - addstr(i+1, 15, "/"); - - if (team_ == llsf_msgs::MAGENTA) { - attron(' '|COLOR_PAIR(COLOR_WHITE_ON_MAGENTA)|A_BOLD); - } else { - attron(' '|COLOR_PAIR(COLOR_MAGENTA_ON_BACK)); - } - printw(i+1, 16, "%u", o.quantity_delivered_magenta()); - switch (o.base_color()) { case llsf_msgs::BASE_RED: @@ -637,7 +635,7 @@ OrderDeliverMenu::On_Menu_Init() case llsf_msgs::BASE_BLACK: attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; } - addstr(i+1, 18, " "); + addstr(i+1, 14, " "); for (int j = 0; j < o.ring_colors_size(); ++j) { switch (o.ring_colors(j)) { @@ -650,12 +648,12 @@ OrderDeliverMenu::On_Menu_Init() case llsf_msgs::RING_YELLOW: attron(' '|COLOR_PAIR(COLOR_BLACK_ON_YELLOW)); break; } - addstr(i+1, 19+j, " "); + addstr(i+1, 15+j, " "); } for (int j = o.ring_colors_size(); j < 4; ++j) { attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); - addstr(i+1, 19+j, " "); + addstr(i+1, 15+j, " "); } switch (o.cap_color()) { @@ -664,10 +662,10 @@ OrderDeliverMenu::On_Menu_Init() case llsf_msgs::CAP_GREY: attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; } - addstr(i+1, 22, " "); + addstr(i+1, 18, " "); attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)); - printw(i+1, 24, "D%u", o.delivery_gate()); + printw(i+1, 20, "D%u", o.delivery_gate()); } refresh(); @@ -675,18 +673,20 @@ OrderDeliverMenu::On_Menu_Init() int OrderDeliverMenu::det_lines(llsf_msgs::Team team, - std::shared_ptr &oinfo) + std::vector> &deliveries) { - if (oinfo) { - return oinfo->orders_size(); - } else { - return 0; + int lines = 0; + for (auto && delivery : deliveries) { + if (delivery->team_color() == team) { + lines++; + } } + return lines; } OrderDeliverMenu::operator bool() const { - return order_selected_; + return delivery_selected_; } diff --git a/src/shell/menus.h b/src/shell/menus.h index 5520de2fb..d84ef1ee8 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -204,22 +204,25 @@ class OrderDeliverMenu : public Menu { public: OrderDeliverMenu(NCursesWindow *parent, llsf_msgs::Team team, + std::vector> deliveries, std::shared_ptr oinfo, std::shared_ptr gstate); - const llsf_msgs::Order & order(); + int delivery() const; operator bool() const; private: virtual void On_Menu_Init(); - int det_lines(llsf_msgs::Team team, std::shared_ptr &oinfo); - void order_selected(int i); + int det_lines(llsf_msgs::Team team, + std::vector> &deliveries); + void delivery_selected(int i); private: std::shared_ptr oinfo_; llsf_msgs::Team team_; - bool order_selected_; - int order_idx_; + bool delivery_selected_; + int delivery_idx_; + bool correct_; std::string s_cancel_; typedef std::pair ItemPair; std::vector items_; diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 4ab55df3f..ab4e1c79d 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -327,10 +327,12 @@ LLSFRefBoxShell::handle_keyboard(const boost::system::error_code& error) tcsm(); if (tcsm) { OrderDeliverMenu odm(panel_, tcsm.get_team_color(), + unconfirmed_deliveries_, last_orderinfo_, last_game_state_); odm(); if (odm) { - send_set_order_delivered(tcsm.get_team_color(), odm.order()); + // TODO: check if the order was correct + send_confirm_delivery(odm.delivery(), true); } } io_service_.dispatch(boost::bind(&LLSFRefBoxShell::refresh, this)); @@ -496,34 +498,21 @@ LLSFRefBoxShell::send_robot_maintenance(llsf_msgs::Team team, } void -LLSFRefBoxShell::send_set_order_delivered(llsf_msgs::Team team, const llsf_msgs::Order &order) +LLSFRefBoxShell::send_confirm_delivery(unsigned int delivery_id, bool correct) { - unsigned int order_id = order.id(); - - llsf_msgs::SetOrderDelivered od; - od.set_team_color(team); - od.set_order_id(order_id); - logf("Sending completed order %u for team %s", order_id, llsf_msgs::Team_Name(team).c_str()); - try { - client->send(od); - } catch (std::runtime_error &e) { - logf("Sending SetOrderDelivered failed: %s", e.what()); - } - - /* - llsf_msgs::SetOrderDeliveredByColor od; - od.set_team_color(team); - od.set_base_color(order.base_color()); - for (int i = 0; i < order.ring_colors_size(); ++i) { - od.add_ring_colors(order.ring_colors(i)); + llsf_msgs::ConfirmDelivery od; + od.set_delivery_id(delivery_id); + od.set_correct(correct); + if (correct) { + logf("Confirming correct delivery %u", delivery_id); + } else { + logf("Confirming incorrect delivery %u", delivery_id); } - od.set_cap_color(order.cap_color()); try { client->send(od); } catch (std::runtime_error &e) { - logf("Sending SetOrderDeliveredByColor failed: %s", e.what()); + logf("Sending ConfirmDelivery failed: %s", e.what()); } - */ } void diff --git a/src/shell/shell.h b/src/shell/shell.h index 4637032b4..049cb0969 100644 --- a/src/shell/shell.h +++ b/src/shell/shell.h @@ -118,7 +118,7 @@ class LLSFRefBoxShell void send_set_team(llsf_msgs::Team team, std::string &team_name); void send_robot_maintenance(llsf_msgs::Team team, unsigned int robot_number, bool maintenance); - void send_set_order_delivered(llsf_msgs::Team team, const llsf_msgs::Order &order); + void send_confirm_delivery(unsigned int delivery_id, bool correct); void log(llsf_log_msgs::LogMessage::LogLevel log_level, long int ts_sec, long int ts_nsec, From c59bf555bd050eb6cbf0199786584ce88bd982ca Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 11:19:40 +0000 Subject: [PATCH 25/54] shell: show correct order configuration in OrderDeliverMenu --- src/shell/menus.cpp | 10 ++++++---- src/shell/menus.h | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 213c8ccbc..d6ddeb40e 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -570,14 +570,14 @@ OrderDeliverMenu::OrderDeliverMenu if (s.empty()) { s = boost::str(boost::format("%2u: ?? ??:??") % delivery->order_id()); } - items_[ni++] = std::make_pair(delivery->order_id(), s); + items_[ni++] = std::make_tuple(delivery->id(), delivery->order_id(), s); } std::sort(items_.begin(), items_.end()); for (int i = 0; i < ni; ++i) { - SignalItem *item = new SignalItem(items_[i].second); + SignalItem *item = new SignalItem(std::get<2>(items_[i])); item->signal().connect(boost::bind(&OrderDeliverMenu::delivery_selected, - this, items_[i].first)); + this, std::get<0>(items_[i]))); mitems[i] = item; } s_cancel_ = "** CANCEL **"; @@ -619,7 +619,9 @@ OrderDeliverMenu::On_Menu_Init() attroff(A_BOLD); for (size_t i = 0; i < items_.size(); ++i) { - const llsf_msgs::Order &o = oinfo_->orders(items_[i].first); + // We must substract 1 because items_[i][1] contains the ID of the order, + // but oinfo_->orders is an array starting at 0 + const llsf_msgs::Order &o = oinfo_->orders(std::get<1>(items_[i]) - 1); if (team_ == llsf_msgs::CYAN) { attron(' '|COLOR_PAIR(COLOR_WHITE_ON_CYAN)|A_BOLD); diff --git a/src/shell/menus.h b/src/shell/menus.h index d84ef1ee8..67b00c673 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -224,8 +225,8 @@ class OrderDeliverMenu : public Menu int delivery_idx_; bool correct_; std::string s_cancel_; - typedef std::pair ItemPair; - std::vector items_; + typedef std::tuple ItemTuple; + std::vector items_; }; From 743032c0745405dc6561d03a64e873e6fff66365 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 11:50:48 +0000 Subject: [PATCH 26/54] shell: do not show confirmed deliveries in OrderDeliverMenu --- src/shell/shell.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index ab4e1c79d..937f934a2 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -500,19 +500,25 @@ LLSFRefBoxShell::send_robot_maintenance(llsf_msgs::Team team, void LLSFRefBoxShell::send_confirm_delivery(unsigned int delivery_id, bool correct) { - llsf_msgs::ConfirmDelivery od; - od.set_delivery_id(delivery_id); - od.set_correct(correct); - if (correct) { - logf("Confirming correct delivery %u", delivery_id); - } else { - logf("Confirming incorrect delivery %u", delivery_id); - } - try { - client->send(od); - } catch (std::runtime_error &e) { - logf("Sending ConfirmDelivery failed: %s", e.what()); - } + unconfirmed_deliveries_.erase( + std::find_if(std::begin(unconfirmed_deliveries_), + std::end(unconfirmed_deliveries_), + [delivery_id](const std::shared_ptr delivery) { + return delivery->id() == delivery_id; + })); + llsf_msgs::ConfirmDelivery od; + od.set_delivery_id(delivery_id); + od.set_correct(correct); + if (correct) { + logf("Confirming correct delivery %u", delivery_id); + } else { + logf("Confirming incorrect delivery %u", delivery_id); + } + try { + client->send(od); + } catch (std::runtime_error &e) { + logf("Sending ConfirmDelivery failed: %s", e.what()); + } } void From d895e79f0b62148003ce8fcbc190cda5465aa57e Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 17:03:43 +0000 Subject: [PATCH 27/54] shell: add a menu after the delivery menu to ask for a correct delivery When we confirm a delivery, we must also be able to confirm an incorrect delivery. Add a new menu after the main delivery menu that shows the product configuration again and asks whether the product was correctly delivered. --- src/shell/menus.cpp | 111 ++++++++++++++++++++++++++++++++++++++++++-- src/shell/menus.h | 31 ++++++++++++- src/shell/shell.cpp | 12 +++-- 3 files changed, 146 insertions(+), 8 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index d6ddeb40e..6f1a62893 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -545,7 +545,7 @@ OrderDeliverMenu::OrderDeliverMenu : Menu(det_lines(team, deliveries) + 1 + 2, 25 + 2, (parent->lines() - (det_lines(team, deliveries) + 1))/2, (parent->cols() - 26)/2), - oinfo_(oinfo), team_(team) + oinfo_(oinfo), deliveries_(deliveries), team_(team) { delivery_selected_ = false; int n_items = det_lines(team, deliveries); @@ -596,10 +596,15 @@ OrderDeliverMenu::delivery_selected(int i) delivery_idx_ = i; } -int +std::shared_ptr OrderDeliverMenu::delivery() const { - return delivery_idx_; + auto delivery = std::find_if(deliveries_.begin(), + deliveries_.end(), + [this](std::shared_ptr delivery) { + return delivery->id() == delivery_idx_; + }); + return *delivery; } void @@ -691,5 +696,105 @@ OrderDeliverMenu::operator bool() const return delivery_selected_; } +DeliveryCorrectMenu::DeliveryCorrectMenu(NCursesWindow * parent, + llsf_msgs::Team team, + std::shared_ptr delivery, + std::shared_ptr oinfo) +: Menu(5, 25 + 2, (parent->lines() - 2) / 2, (parent->cols() - 26) / 2), + delivery_(delivery), + correct_(false), + correct_selected_(false), + oinfo_(oinfo), + team_(team), + s_yes_("YES"), + s_no_("NO"), + s_cancel_("CANCEL") +{ + NCursesMenuItem **mitems = new NCursesMenuItem *[4]; + SignalItem *yes_item = new SignalItem(s_yes_); + yes_item->signal().connect(boost::bind(&DeliveryCorrectMenu::correct_selected, this, true)); + int idx = 0; + mitems[idx++] = yes_item; + SignalItem *no_item = new SignalItem(s_no_); + no_item->signal().connect(boost::bind(&DeliveryCorrectMenu::correct_selected, this, false)); + mitems[idx++] = no_item; + SignalItem *cancel_item = new SignalItem(s_cancel_); + mitems[idx++] = cancel_item; + mitems[idx++] = new NCursesMenuItem(); + set_mark(""); + set_format(idx-1, 1); + InitMenu(mitems, true, true); +} + +void +DeliveryCorrectMenu::On_Menu_Init() +{ + bkgd(' ' | COLOR_PAIR(COLOR_DEFAULT)); + + if (team_ == llsf_msgs::CYAN) { + attron(' ' | COLOR_PAIR(COLOR_CYAN_ON_BACK)); + } else { + attron(' ' | COLOR_PAIR(COLOR_MAGENTA_ON_BACK)); + } + box(); + + attron(' ' | COLOR_PAIR(COLOR_BLACK_ON_BACK) | A_BOLD); + addstr(0, (width() - 18) / 2, " Correct Delivery? "); + attroff(A_BOLD); + + + const llsf_msgs::Order &o = + *std::find_if(oinfo_->orders().begin(), + oinfo_->orders().end(), + [this](const llsf_msgs::Order &o) { return o.id() == delivery_->order_id(); }); + printw(1, 14, "C%u", o.complexity()); + switch (o.base_color()) { + case llsf_msgs::BASE_RED: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_RED)); break; + case llsf_msgs::BASE_SILVER: attron(' ' | COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; + case llsf_msgs::BASE_BLACK: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; + } + addstr(2, 14, " "); + + for (int j = 0; j < o.ring_colors_size(); ++j) { + switch (o.ring_colors(j)) { + case llsf_msgs::RING_BLUE: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_BLUE)); break; + case llsf_msgs::RING_GREEN: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_GREEN)); break; + case llsf_msgs::RING_ORANGE: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_ORANGE)); break; + case llsf_msgs::RING_YELLOW: attron(' ' | COLOR_PAIR(COLOR_BLACK_ON_YELLOW)); break; + } + addstr(2, 15 + j, " "); + } + + for (int j = o.ring_colors_size(); j < 4; ++j) { + attron(' ' | COLOR_PAIR(COLOR_BLACK_ON_WHITE)); + addstr(2, 15 + j, " "); + } + + switch (o.cap_color()) { + case llsf_msgs::CAP_BLACK: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; + case llsf_msgs::CAP_GREY: attron(' ' | COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; + } + addstr(2, 18, " "); + + attron(' ' | COLOR_PAIR(COLOR_BLACK_ON_BACK)); + printw(3, 14, "D%u", o.delivery_gate()); + refresh(); +} + +void +DeliveryCorrectMenu::correct_selected(bool correct) { + correct_selected_ = true; + correct_ = correct; +} + +bool +DeliveryCorrectMenu::correct() const { + return correct_; +} + +DeliveryCorrectMenu::operator bool() const +{ + return correct_selected_; +} } // end of namespace llsfrb diff --git a/src/shell/menus.h b/src/shell/menus.h index 67b00c673..bcf4c1c18 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -209,7 +209,7 @@ class OrderDeliverMenu : public Menu std::shared_ptr oinfo, std::shared_ptr gstate); - int delivery() const; + std::shared_ptr delivery() const; operator bool() const; private: @@ -220,15 +220,42 @@ class OrderDeliverMenu : public Menu private: std::shared_ptr oinfo_; + std::vector> deliveries_; llsf_msgs::Team team_; bool delivery_selected_; - int delivery_idx_; + unsigned int delivery_idx_; bool correct_; std::string s_cancel_; typedef std::tuple ItemTuple; std::vector items_; }; +class DeliveryCorrectMenu : public Menu +{ +public: + DeliveryCorrectMenu(NCursesWindow * parent, + llsf_msgs::Team team, + std::shared_ptr delivery, + std::shared_ptr oinfo); + + bool correct() const; + operator bool() const; + +private: + virtual void On_Menu_Init(); + void correct_selected(bool); + +private: + std::shared_ptr delivery_; + bool correct_; + bool correct_selected_; + std::shared_ptr oinfo_; + llsf_msgs::Team team_; + std::string s_yes_; + std::string s_no_; + std::string s_cancel_; +}; + } // end of namespace llsfrb diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 937f934a2..7b6f1d4cc 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -331,9 +331,15 @@ LLSFRefBoxShell::handle_keyboard(const boost::system::error_code& error) last_orderinfo_, last_game_state_); odm(); if (odm) { - // TODO: check if the order was correct - send_confirm_delivery(odm.delivery(), true); - } + DeliveryCorrectMenu dcm(panel_, + tcsm.get_team_color(), + odm.delivery(), + last_orderinfo_); + dcm(); + if (dcm) { + send_confirm_delivery(odm.delivery()->id(), dcm.correct()); + } + } } io_service_.dispatch(boost::bind(&LLSFRefBoxShell::refresh, this)); } From b07463737996351540dfb137ec8ec619a93db36f Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 17:05:06 +0000 Subject: [PATCH 28/54] shell: fix time display in delivery menu --- src/shell/menus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 6f1a62893..79c3dcda1 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -560,7 +560,7 @@ OrderDeliverMenu::OrderDeliverMenu for (int j = 0; j < oinfo->orders_size(); ++j) { const llsf_msgs::Order &o = oinfo->orders(j); if (o.id() == delivery->order_id()) { - s = boost::str(boost::format("%2u: %2s %2u:%2u") + s = boost::str(boost::format("%2u: %2s %02u:%02u") % o.id() % llsf_msgs::Order::Complexity_Name(o.complexity()) % min % sec); From 4e9fe554240c5011f837d4f52a1f890e030469a8 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 17:05:29 +0000 Subject: [PATCH 29/54] shell: do not show deliveries without an order in DeliveryMenu We may have a delivery that has no known order ID. In that case, just don't show the delivery at all, instead of showing question marks. --- src/shell/menus.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 79c3dcda1..a84807a94 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -564,14 +564,11 @@ OrderDeliverMenu::OrderDeliverMenu % o.id() % llsf_msgs::Order::Complexity_Name(o.complexity()) % min % sec); + items_[ni++] = std::make_tuple(delivery->id(), delivery->order_id(), s); break; - } - } - if (s.empty()) { - s = boost::str(boost::format("%2u: ?? ??:??") % delivery->order_id()); + } } - items_[ni++] = std::make_tuple(delivery->id(), delivery->order_id(), s); - } + } std::sort(items_.begin(), items_.end()); for (int i = 0; i < ni; ++i) { From e72be1b7719dbb1ff892487867bdcfb29eba6e2e Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 17:38:17 +0000 Subject: [PATCH 30/54] shell: only show deliveries of the selected team in OrderDeliverMenu --- src/shell/menus.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index a84807a94..120d62601 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -552,9 +552,9 @@ OrderDeliverMenu::OrderDeliverMenu items_.resize(n_items); int ni = 0; NCursesMenuItem **mitems = new NCursesMenuItem*[2 + n_items]; - for (size_t i = 0; i < deliveries.size(); i++) { - std::shared_ptr delivery = deliveries[i]; - int min = delivery->delivery_time().sec() / 60; + for (auto && delivery : deliveries) { + if (delivery->team_color() != team) { continue; } + int min = delivery->delivery_time().sec() / 60; int sec = delivery->delivery_time().sec() - min * 60; std::string s; for (int j = 0; j < oinfo->orders_size(); ++j) { From 95485a7f80bd663786187b06b41654440447b86d Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 17:49:22 +0000 Subject: [PATCH 31/54] rcll: do not give points for incorrect deliveries If we get a ConfirmDelivery msg that has the field 'correct' set to false, then retract the product-delivered fact and do not give any points for that delivery. --- src/games/rcll/orders.clp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 59169c246..1dc27dabb 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -46,9 +46,14 @@ ((?pd product-delivered)) (and (eq ?pd:id (pb-field-value ?p "delivery_id")) (eq ?pd:confirmed FALSE)) - (printout t "Confirmed delivery of order " ?pd:order - " by team " ?pd:team crlf) - (modify ?pd (confirmed TRUE)))) + (if (eq (pb-field-value ?p "correct") 1) then + (printout t "Correct delivery for order " ?pd:order + " by team " ?pd:team crlf) + (modify ?pd (confirmed TRUE))) + else + (printout t "Delivery for order " ?pd:order " by team " ?pd:team + " was incorrect!" crlf) + (retract ?pd))) then (printout error "Received invalid SetOrderDelivered" " (order " (pb-field-value ?p "order_id") From eb9456158e7b00ad1d9475c57779dd1a611ddfa4 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 18:08:30 +0000 Subject: [PATCH 32/54] shell: fix array access in OrderDeliverMenu Accessing the order from the oinfo only works by index if we have all orders in our list, which is not true anymore. Thus, instead of relying on using the index as order ID, find the order that has the same ID as the order ID in the current item. --- src/shell/menus.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 120d62601..c8c17f25d 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -621,9 +621,11 @@ OrderDeliverMenu::On_Menu_Init() attroff(A_BOLD); for (size_t i = 0; i < items_.size(); ++i) { - // We must substract 1 because items_[i][1] contains the ID of the order, - // but oinfo_->orders is an array starting at 0 - const llsf_msgs::Order &o = oinfo_->orders(std::get<1>(items_[i]) - 1); + const llsf_msgs::Order &o = *std::find_if(oinfo_->orders().begin(), + oinfo_->orders().end(), + [this, i](const llsf_msgs::Order &o) { + return o.id() == std::get<1>(items_[i]); + }); if (team_ == llsf_msgs::CYAN) { attron(' '|COLOR_PAIR(COLOR_WHITE_ON_CYAN)|A_BOLD); From 699d0ee3bc77808b73387d4416a3695b05d8bb2a Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 18:15:21 +0000 Subject: [PATCH 33/54] rcll-prepare-machine: make sure we have the right #args for the DS --- src/tools/rcll-prepare-machine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tools/rcll-prepare-machine.cpp b/src/tools/rcll-prepare-machine.cpp index 5e5e490a0..95fc53ebd 100644 --- a/src/tools/rcll-prepare-machine.cpp +++ b/src/tools/rcll-prepare-machine.cpp @@ -237,6 +237,11 @@ main(int argc, char **argv) printf("Invalid base color\n"); exit(-2); } } else if (machine_type_ == "DS") { + if (argp.num_items() != 4) { + printf("Wrong number of arguments. Expected 4, got %zu\n", argp.num_items()); + usage(argv[0]); + exit(-1); + } ds_gate_ = argp.parse_item_int(2); ds_order_id_ = argp.parse_item_int(3); } else if (machine_type_ == "SS") { From 1b3a36f693b233225e16df8f3b2cd19d7d9dbf80 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 24 Jan 2019 18:17:09 +0000 Subject: [PATCH 34/54] rcll-prepare-machine: switch the order of arguments for the DS --- src/tools/rcll-prepare-machine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/rcll-prepare-machine.cpp b/src/tools/rcll-prepare-machine.cpp index 95fc53ebd..a0cea26da 100644 --- a/src/tools/rcll-prepare-machine.cpp +++ b/src/tools/rcll-prepare-machine.cpp @@ -202,7 +202,7 @@ usage(const char *progname) "\n" "instructions are specific for the machine type:\n" "BS: (INPUT|OUTPUT) (BASE_RED|BASE_BLACK|BASE_SILVER)\n" - "DS: \n" + "DS: \n" "SS: (RETRIEVE|STORE) \n" "RS: (RING_BLUE|RING_GREEN|RING_ORANGE|RING_YELLOW)\n" "CS: (RETRIEVE_CAP|MOUNT_CAP)\n", @@ -242,8 +242,8 @@ main(int argc, char **argv) usage(argv[0]); exit(-1); } - ds_gate_ = argp.parse_item_int(2); - ds_order_id_ = argp.parse_item_int(3); + ds_order_id_ = argp.parse_item_int(2); + ds_gate_ = argp.parse_item_int(3); } else if (machine_type_ == "SS") { if (argp.num_items() < 6) { printf("SS machine requires operation and x, y, z arguments %zu\n", argp.num_items()); From 23038f84e01a4379fe66c1fbd7cec10f2a73cbe7 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 13:46:27 +0000 Subject: [PATCH 35/54] rcll: only process OrderDelivered msg when in PRODUCTION or POST_GAME --- src/games/rcll/orders.clp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 1dc27dabb..e37645245 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -40,6 +40,7 @@ ) (defrule order-recv-SetOrderDelivered + (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (protobuf-msg (type "llsf_msgs.ConfirmDelivery") (ptr ?p) (rcvd-via STREAM)) => (if (not (do-for-fact From a68a4366f45b065dee7d0709cf32e624875193c3 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 13:50:01 +0000 Subject: [PATCH 36/54] rcll: also compute score when not in PRODUCTION or not RUNNING --- src/games/rcll/orders.clp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index e37645245..2bcdff55b 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -65,7 +65,7 @@ (defrule order-delivered-correct - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION)) + ?gf <- (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (product-delivered (game-time ?delivery-time) (team ?team) (order ?id&~0) (delivery-gate ?gate) (confirmed TRUE)) @@ -153,7 +153,7 @@ ) (defrule order-delivered-invalid - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) + ?gf <- (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?order)) (not (order (id ?order))) => @@ -165,7 +165,7 @@ ) (defrule order-delivered-wrong-delivgate - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) + ?gf <- (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) (delivery-gate ?gate) (order ?id) (confirmed TRUE)) ; the actual order we are delivering @@ -181,7 +181,7 @@ ) (defrule order-delivered-wrong-too-soon - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) + ?gf <- (gamestate (phase PRODUCTION|POST_GAME) (game-time ?gt)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?id) (confirmed TRUE)) ; the actual order we are delivering @@ -197,7 +197,7 @@ ) (defrule order-delivered-wrong-too-many - ?gf <- (gamestate (state RUNNING) (phase PRODUCTION) (game-time ?gt)) + ?gf <- (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?id) (confirmed TRUE)) ; the actual order we are delivering From d2f9098c2593633d4874c7eb0ad4100e9539cbe5 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 13:51:12 +0000 Subject: [PATCH 37/54] rcll: base decision whether the delivery was too early on delivery time When deciding whether a delivery was too early, do not use the current game time, but the time of the delivery. --- src/games/rcll/orders.clp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 2bcdff55b..66017b202 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -181,11 +181,11 @@ ) (defrule order-delivered-wrong-too-soon - ?gf <- (gamestate (phase PRODUCTION|POST_GAME) (game-time ?gt)) + ?gf <- (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (product-delivered (game-time ?game-time) (team ?team) (order ?id) (confirmed TRUE)) ; the actual order we are delivering - (order (id ?id) (active TRUE) (delivery-period $?dp&:(< ?gt (nth$ 1 ?dp)))) + (order (id ?id) (active TRUE) (delivery-period $?dp&:(< ?game-time (nth$ 1 ?dp)))) => (retract ?pf) (printout warn "Delivered item for order " ?id " (too soon, before time window)" crlf) From 90ec2096890e764a51fbc34e82749faca7eec6f1 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 14:29:34 +0000 Subject: [PATCH 38/54] rcll: only print game summary after all deliveries have been confirmed At the end of the game, we print a summary including the score of each team. To get the correct scores, wait until all deliveries have been confirmed, and only print the summary when there is no unconfirmed delivery. --- src/games/rcll/game.clp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/games/rcll/game.clp b/src/games/rcll/game.clp index 64fecc774..b3da9fc35 100644 --- a/src/games/rcll/game.clp +++ b/src/games/rcll/game.clp @@ -325,6 +325,12 @@ (game-print-points-team MAGENTA) ) +(deffunction game-summary () + (game-print-points) + (assert (attention-message (text "Game Over") (time 60))) + (printout t "=== Game Over ===" crlf) +) + (defrule game-over ?gs <- (gamestate (refbox-mode STANDALONE) (phase PRODUCTION) (state RUNNING) (over-time FALSE) (points ?p-cyan ?p-magenta&:(<> ?p-cyan ?p-magenta)) @@ -357,7 +363,18 @@ (delayed-do-for-all-facts ((?machine machine)) TRUE (modify ?machine (desired-lights RED-BLINK)) ) - (game-print-points) - (assert (attention-message (text "Game Over") (time 60))) - (printout t "=== Game Over ===" crlf) + (if (any-factp ((?pd product-delivered)) TRUE) then + (assert (attention-message (text "Game ended, please confirm deliveries!"))) + (assert (postgame-for-unconfirmed-deliveries)) + else + (game-summary) + ) +) + +(defrule game-postgame-no-unconfirmed-deliveries + ?w <- (postgame-for-unconfirmed-deliveries) + (not (product-delivered)) + => + (retract ?w) + (game-summary) ) From e9dcd55605652d3a5a62da754e140c297cee21f9 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 14:35:28 +0000 Subject: [PATCH 39/54] rcll: improve msg in case of incorrect delivery, fix wrong parentheses Make the message shorter so it better fits into the output of the shell. Fix a misplaced paranthesis that caused the message about the incorrect delivery to always appear. --- src/games/rcll/orders.clp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 66017b202..5da443f35 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -50,11 +50,11 @@ (if (eq (pb-field-value ?p "correct") 1) then (printout t "Correct delivery for order " ?pd:order " by team " ?pd:team crlf) - (modify ?pd (confirmed TRUE))) + (modify ?pd (confirmed TRUE)) else - (printout t "Delivery for order " ?pd:order " by team " ?pd:team - " was incorrect!" crlf) - (retract ?pd))) + (printout t "Incorrect delivery for order " ?pd:order + " by team " ?pd:team crlf) + (retract ?pd)))) then (printout error "Received invalid SetOrderDelivered" " (order " (pb-field-value ?p "order_id") From 2a1fb877a5225654341dbaccd6a2c556988032f9 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 15:00:06 +0000 Subject: [PATCH 40/54] shell: show "UNKNOWN" in OrderDeliverMenu if order cannot be found The function find_if may return an end iterator. In that case, instead of failing, show the string "UNKNOWN" in place of the order configuration. --- src/shell/menus.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index c8c17f25d..847c1b350 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -621,11 +621,16 @@ OrderDeliverMenu::On_Menu_Init() attroff(A_BOLD); for (size_t i = 0; i < items_.size(); ++i) { - const llsf_msgs::Order &o = *std::find_if(oinfo_->orders().begin(), - oinfo_->orders().end(), - [this, i](const llsf_msgs::Order &o) { - return o.id() == std::get<1>(items_[i]); - }); + auto order_p = std::find_if(oinfo_->orders().begin(), + oinfo_->orders().end(), + [this, i](const llsf_msgs::Order &o) { + return o.id() == std::get<1>(items_[i]); + }); + if (order_p == oinfo_->orders().end()) { + addstr(i + 1, 14, "UNKNOWN"); + continue; + } + const llsf_msgs::Order &o = *order_p; if (team_ == llsf_msgs::CYAN) { attron(' '|COLOR_PAIR(COLOR_WHITE_ON_CYAN)|A_BOLD); From 2feb3ef0189e87c1b0b7b22af956c4ed29c56286 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 15:05:41 +0000 Subject: [PATCH 41/54] shell: show "UNKNOWN" in DeliveryCorrectMenu if order cannot be found The function find_if may return an end iterator. In that case, instead of failing, show the string "UNKNOWN" in place of the order configuration. --- src/shell/menus.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 847c1b350..e93d68c07 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -746,11 +746,17 @@ DeliveryCorrectMenu::On_Menu_Init() addstr(0, (width() - 18) / 2, " Correct Delivery? "); attroff(A_BOLD); + auto order_p = + std::find_if(oinfo_->orders().begin(), + oinfo_->orders().end(), + [this](const llsf_msgs::Order &o) { return o.id() == delivery_->order_id(); }); + if (order_p == oinfo_->orders().end()) { + printw(1, 14, "UNKNOWN"); + refresh(); + return; + } - const llsf_msgs::Order &o = - *std::find_if(oinfo_->orders().begin(), - oinfo_->orders().end(), - [this](const llsf_msgs::Order &o) { return o.id() == delivery_->order_id(); }); + const llsf_msgs::Order &o = *order_p; printw(1, 14, "C%u", o.complexity()); switch (o.base_color()) { case llsf_msgs::BASE_RED: attron(' ' | COLOR_PAIR(COLOR_WHITE_ON_RED)); break; From 2d674a370e7accdfe832e1e43c0e9146697bb722 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 21:59:43 +0000 Subject: [PATCH 42/54] msgs: add back SetOrderDelivered message As a fallback solution, we may still want to be able to set an order as delivered, even if no delivery was reported. In order to do that, add back the SetOrderDelivered message. --- src/msgs/OrderInfo.proto | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/msgs/OrderInfo.proto b/src/msgs/OrderInfo.proto index e8804e33c..3d44c4287 100644 --- a/src/msgs/OrderInfo.proto +++ b/src/msgs/OrderInfo.proto @@ -93,6 +93,16 @@ message OrderInfo { repeated Order orders = 1; } +message SetOrderDelivered { + enum CompType { + COMP_ID = 2000; + MSG_TYPE = 43; + } + + required Team team_color = 1; + required uint32 order_id = 2; +} + message UnconfirmedDelivery { enum CompType { COMP_ID = 2000; From 516fc1f19fe3ac433789726f4258426d5f71e1ae Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 22:06:39 +0000 Subject: [PATCH 43/54] rcll: process SetOrderDelivered message If we receive a SetOrderDelivered message, assert a new product-delivered fact and directly set it to confirmed. --- src/games/rcll/orders.clp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index 5da443f35..aae520b0d 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -40,6 +40,16 @@ ) (defrule order-recv-SetOrderDelivered + (gamestate (phase PRODUCTION) (game-time ?gt)) + ?pf <- (protobuf-msg (type "llsf_msgs.SetOrderDelivered") (ptr ?p) (rcvd-via STREAM)) + => + (bind ?team (pb-field-value ?p "team_color")) + (bind ?order (pb-field-value ?p "order_id")) + (assert (product-delivered (game-time ?gt) (team ?team) (order ?order) (confirmed TRUE))) + (printout t "Delivery by team " ?team " for order " ?order " reported!" crlf) +) + +(defrule order-recv-ConfirmDelivery (gamestate (phase PRODUCTION|POST_GAME)) ?pf <- (protobuf-msg (type "llsf_msgs.ConfirmDelivery") (ptr ?p) (rcvd-via STREAM)) => From e2b8699a1a73e52b246fbde2ba44438f436e4844 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 22:20:56 +0000 Subject: [PATCH 44/54] shell: add show-all option to OrderDeliverMenu We may want to select an order that has not been reported as delivered, which will be shown if the user selects SHOW ALL. Currently, selecting SHOW ALL will not do anything yet. --- src/shell/menus.cpp | 30 ++++++++++++++++++++++++------ src/shell/menus.h | 4 ++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index e93d68c07..f37539169 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -542,7 +542,7 @@ OrderDeliverMenu::OrderDeliverMenu std::vector> deliveries, std::shared_ptr oinfo, std::shared_ptr gstate) - : Menu(det_lines(team, deliveries) + 1 + 2, 25 + 2, + : Menu(det_lines(team, deliveries) + 1 + 2 + 1, 25 + 2, (parent->lines() - (det_lines(team, deliveries) + 1))/2, (parent->cols() - 26)/2), oinfo_(oinfo), deliveries_(deliveries), team_(team) @@ -551,7 +551,7 @@ OrderDeliverMenu::OrderDeliverMenu int n_items = det_lines(team, deliveries); items_.resize(n_items); int ni = 0; - NCursesMenuItem **mitems = new NCursesMenuItem*[2 + n_items]; + NCursesMenuItem **mitems = new NCursesMenuItem*[3 + n_items]; for (auto && delivery : deliveries) { if (delivery->team_color() != team) { continue; } int min = delivery->delivery_time().sec() / 60; @@ -577,15 +577,27 @@ OrderDeliverMenu::OrderDeliverMenu this, std::get<0>(items_[i]))); mitems[i] = item; } + + s_show_all_ = "** SHOW ALL **"; + SignalItem *show_all_item = new SignalItem(s_show_all_); + show_all_item->signal().connect(boost::bind(&OrderDeliverMenu::show_all_selected, this)); + mitems[ni] = show_all_item; + s_cancel_ = "** CANCEL **"; - mitems[ni] = new SignalItem(s_cancel_); - mitems[ni+1] = new NCursesMenuItem(); + mitems[ni + 1] = new SignalItem(s_cancel_); + mitems[ni + 2] = new NCursesMenuItem(); set_mark(""); - set_format(ni+1, 1); + set_format(ni+2, 1); InitMenu(mitems, true, true); } +void +OrderDeliverMenu::show_all_selected() +{ + show_all_selected_ = true; +} + void OrderDeliverMenu::delivery_selected(int i) { @@ -604,6 +616,12 @@ OrderDeliverMenu::delivery() const return *delivery; } +bool +OrderDeliverMenu::show_all() const +{ + return show_all_selected_; +} + void OrderDeliverMenu::On_Menu_Init() { @@ -697,7 +715,7 @@ OrderDeliverMenu::det_lines(llsf_msgs::Team team, OrderDeliverMenu::operator bool() const { - return delivery_selected_; + return show_all_selected_ || delivery_selected_; } DeliveryCorrectMenu::DeliveryCorrectMenu(NCursesWindow * parent, diff --git a/src/shell/menus.h b/src/shell/menus.h index bcf4c1c18..d01db0add 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -210,21 +210,25 @@ class OrderDeliverMenu : public Menu std::shared_ptr gstate); std::shared_ptr delivery() const; + bool show_all() const; operator bool() const; private: virtual void On_Menu_Init(); int det_lines(llsf_msgs::Team team, std::vector> &deliveries); + void show_all_selected(); void delivery_selected(int i); private: std::shared_ptr oinfo_; std::vector> deliveries_; llsf_msgs::Team team_; + bool show_all_selected_; bool delivery_selected_; unsigned int delivery_idx_; bool correct_; + std::string s_show_all_; std::string s_cancel_; typedef std::tuple ItemTuple; std::vector items_; From d8f26e1560ddf2d97557b166a15561eddd9d0d82 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 22:36:49 +0000 Subject: [PATCH 45/54] shell: add (back) SelectOrderByIDMenu This is basically the same as the old OrderDeliverMenu. It allows to select a delivery for every order, including orders where no delivery has been reported. --- src/shell/menus.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++++ src/shell/menus.h | 25 ++++++++ 2 files changed, 178 insertions(+) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index f37539169..80e61fe45 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -718,6 +718,159 @@ OrderDeliverMenu::operator bool() const return show_all_selected_ || delivery_selected_; } +SelectOrderByIDMenu::SelectOrderByIDMenu + (NCursesWindow *parent, llsf_msgs::Team team, + std::shared_ptr oinfo, + std::shared_ptr gstate) + : Menu(det_lines(team, oinfo) + 1 + 2, 25 + 2, + (parent->lines() - (det_lines(team, oinfo) + 1))/2, + (parent->cols() - 26)/2), + oinfo_(oinfo), team_(team) +{ + order_selected_ = false; + int n_items = det_lines(team, oinfo); + items_.resize(n_items); + int ni = 0; + NCursesMenuItem **mitems = new NCursesMenuItem*[2 + n_items]; + for (int i = 0; i < oinfo->orders_size(); ++i) { + const llsf_msgs::Order &o = oinfo->orders(i); + + bool active = (gstate->game_time().sec() >= o.delivery_period_begin() && + gstate->game_time().sec() <= o.delivery_period_end()); + + std::string s = boost::str(boost::format("%s %2u: %u x %2s") + % (active ? "*" : " ") % o.id() % o.quantity_requested() + % llsf_msgs::Order::Complexity_Name(o.complexity())); + items_[ni++] = std::make_pair(i, s); + } + std::sort(items_.begin(), items_.end()); + + for (int i = 0; i < ni; ++i) { + SignalItem *item = new SignalItem(items_[i].second); + item->signal().connect(boost::bind(&SelectOrderByIDMenu::order_selected, + this, items_[i].first)); + mitems[i] = item; + } + s_cancel_ = "** CANCEL **"; + mitems[ni] = new SignalItem(s_cancel_); + mitems[ni+1] = new NCursesMenuItem(); + + set_mark(""); + set_format(ni+1, 1); + InitMenu(mitems, true, true); +} + +void +SelectOrderByIDMenu::order_selected(int i) +{ + order_selected_ = true; + order_idx_ = i; +} + +const llsf_msgs::Order & +SelectOrderByIDMenu::order() +{ + return oinfo_->orders(order_idx_); +} + +void +SelectOrderByIDMenu::On_Menu_Init() +{ + bkgd(' '|COLOR_PAIR(COLOR_DEFAULT)); + + if (team_ == llsf_msgs::CYAN) { + attron(' '|COLOR_PAIR(COLOR_CYAN_ON_BACK)); + } else { + attron(' '|COLOR_PAIR(COLOR_MAGENTA_ON_BACK)); + } + box(); + + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)|A_BOLD); + addstr(0, (width() - 8) / 2, " Orders "); + attroff(A_BOLD); + + for (size_t i = 0; i < items_.size(); ++i) { + const llsf_msgs::Order &o = oinfo_->orders(items_[i].first); + + if (team_ == llsf_msgs::CYAN) { + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_CYAN)|A_BOLD); + } else { + attron(' '|COLOR_PAIR(COLOR_CYAN_ON_BACK)); + } + printw(i+1, 14, "%u", o.quantity_delivered_cyan()); + + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)); + addstr(i+1, 15, "/"); + + if (team_ == llsf_msgs::MAGENTA) { + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_MAGENTA)|A_BOLD); + } else { + attron(' '|COLOR_PAIR(COLOR_MAGENTA_ON_BACK)); + } + printw(i+1, 16, "%u", o.quantity_delivered_magenta()); + + + switch (o.base_color()) { + case llsf_msgs::BASE_RED: + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_RED)); break; + case llsf_msgs::BASE_SILVER: + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; + case llsf_msgs::BASE_BLACK: + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; + } + addstr(i+1, 18, " "); + + for (int j = 0; j < o.ring_colors_size(); ++j) { + switch (o.ring_colors(j)) { + case llsf_msgs::RING_BLUE: + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLUE)); break; + case llsf_msgs::RING_GREEN: + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_GREEN)); break; + case llsf_msgs::RING_ORANGE: + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_ORANGE)); break; + case llsf_msgs::RING_YELLOW: + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_YELLOW)); break; + } + addstr(i+1, 19+j, " "); + } + + for (int j = o.ring_colors_size(); j < 4; ++j) { + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); + addstr(i+1, 19+j, " "); + } + + switch (o.cap_color()) { + case llsf_msgs::CAP_BLACK: + attron(' '|COLOR_PAIR(COLOR_WHITE_ON_BLACK)); break; + case llsf_msgs::CAP_GREY: + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_WHITE)); break; + } + addstr(i+1, 22, " "); + + attron(' '|COLOR_PAIR(COLOR_BLACK_ON_BACK)); + printw(i+1, 24, "D%u", o.delivery_gate()); + } + + refresh(); +} + +int +SelectOrderByIDMenu::det_lines(llsf_msgs::Team team, + std::shared_ptr &oinfo) +{ + if (oinfo) { + return oinfo->orders_size(); + } else { + return 0; + } +} + +SelectOrderByIDMenu::operator bool() const +{ + return order_selected_; +} + + DeliveryCorrectMenu::DeliveryCorrectMenu(NCursesWindow * parent, llsf_msgs::Team team, std::shared_ptr delivery, diff --git a/src/shell/menus.h b/src/shell/menus.h index d01db0add..1149e67e7 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -234,6 +234,31 @@ class OrderDeliverMenu : public Menu std::vector items_; }; +class SelectOrderByIDMenu : public Menu +{ +public: + SelectOrderByIDMenu(NCursesWindow * parent, + llsf_msgs::Team team, + std::shared_ptr oinfo, + std::shared_ptr gstate); + const llsf_msgs::Order &order(); + operator bool() const; + +private: + virtual void On_Menu_Init(); + int det_lines(llsf_msgs::Team team, std::shared_ptr & oinfo); + void order_selected(int i); + +private: + std::shared_ptr oinfo_; + llsf_msgs::Team team_; + bool order_selected_; + int order_idx_; + std::string s_cancel_; + typedef std::pair ItemPair; + std::vector items_; +}; + class DeliveryCorrectMenu : public Menu { public: From bd1fb3f5314dd093d494dddedb607767fba6fa23 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Fri, 25 Jan 2019 22:58:09 +0000 Subject: [PATCH 46/54] shell: show SelectOrderByIDMenu if SHOWALL is selected in DeliveryMenu The menu shows all available orders and reports a confirmed delivery for the selected order. --- src/shell/shell.cpp | 46 ++++++++++++++++++++++++++++++--------------- src/shell/shell.h | 1 + 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 7b6f1d4cc..37c166ed2 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -325,22 +325,25 @@ LLSFRefBoxShell::handle_keyboard(const boost::system::error_code& error) } else { TeamColorSelectMenu tcsm(panel_); tcsm(); - if (tcsm) { - OrderDeliverMenu odm(panel_, tcsm.get_team_color(), - unconfirmed_deliveries_, - last_orderinfo_, last_game_state_); - odm(); - if (odm) { - DeliveryCorrectMenu dcm(panel_, - tcsm.get_team_color(), - odm.delivery(), - last_orderinfo_); - dcm(); - if (dcm) { - send_confirm_delivery(odm.delivery()->id(), dcm.correct()); - } + if (tcsm) { + OrderDeliverMenu odm( + panel_, tcsm.get_team_color(), unconfirmed_deliveries_, last_orderinfo_, last_game_state_); + odm(); + if (odm) { + if (odm.show_all()) { + SelectOrderByIDMenu oidm(panel_, + tcsm.get_team_color(), + last_orderinfo_, + last_game_state_); + oidm(); + if (oidm) { send_delivery_by_order_id(oidm.order().id(), tcsm.get_team_color()); } + } else { + DeliveryCorrectMenu dcm(panel_, tcsm.get_team_color(), odm.delivery(), last_orderinfo_); + dcm(); + if (dcm) { send_confirm_delivery(odm.delivery()->id(), dcm.correct()); } + } } - } + } io_service_.dispatch(boost::bind(&LLSFRefBoxShell::refresh, this)); } break; @@ -527,6 +530,19 @@ LLSFRefBoxShell::send_confirm_delivery(unsigned int delivery_id, bool correct) } } +void +LLSFRefBoxShell::send_delivery_by_order_id(unsigned int order_id, llsf_msgs::Team team) +{ + llsf_msgs::SetOrderDelivered od; + od.set_order_id(order_id); + od.set_team_color(team); + try { + client->send(od); + } catch(std::runtime_error &e) { + logf("Sending SetOrderDelivered failed: %s", e.what()); + } +} + void LLSFRefBoxShell::client_connected() { diff --git a/src/shell/shell.h b/src/shell/shell.h index 049cb0969..d0b8eae1f 100644 --- a/src/shell/shell.h +++ b/src/shell/shell.h @@ -119,6 +119,7 @@ class LLSFRefBoxShell void send_robot_maintenance(llsf_msgs::Team team, unsigned int robot_number, bool maintenance); void send_confirm_delivery(unsigned int delivery_id, bool correct); + void send_delivery_by_order_id(unsigned int order_id, llsf_msgs::Team team); void log(llsf_log_msgs::LogMessage::LogLevel log_level, long int ts_sec, long int ts_nsec, From d8bace1bb8678d7d517686dd5411831532ca17a5 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Sat, 26 Jan 2019 10:36:26 +0000 Subject: [PATCH 47/54] rcll: make sure do-for-fact evaluates to TRUE in ConfirmDelivery check --- src/games/rcll/orders.clp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/games/rcll/orders.clp b/src/games/rcll/orders.clp index aae520b0d..ea36c272f 100644 --- a/src/games/rcll/orders.clp +++ b/src/games/rcll/orders.clp @@ -64,7 +64,9 @@ else (printout t "Incorrect delivery for order " ?pd:order " by team " ?pd:team crlf) - (retract ?pd)))) + (retract ?pd)) + ; make sure do-for-fact evaluates to TRUE + TRUE)) then (printout error "Received invalid SetOrderDelivered" " (order " (pb-field-value ?p "order_id") From ee71cc9f01d3f4e84392cd4f80d8659f10217541 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 14 Feb 2019 11:39:22 +0100 Subject: [PATCH 48/54] msgs: make UnconfirmedDelivery a repeated sub-field of the order Instead of sending a separate message, the info about unconfirmed deliveries will be sent as part of the OrderInfo. --- src/msgs/OrderInfo.proto | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/msgs/OrderInfo.proto b/src/msgs/OrderInfo.proto index 3d44c4287..ac81d1185 100644 --- a/src/msgs/OrderInfo.proto +++ b/src/msgs/OrderInfo.proto @@ -45,6 +45,16 @@ import "ProductColor.proto"; option java_package = "org.robocup_logistics.llsf_msgs"; option java_outer_classname = "OrderInfoProtos"; +message UnconfirmedDelivery { + enum CompType { + COMP_ID = 2000; + MSG_TYPE = 45; + } + + required uint32 id = 1; + required Time delivery_time = 2; +} + message Order { enum CompType { COMP_ID = 2000; @@ -81,6 +91,8 @@ message Order { // (non-defunct, i.e. non-red light) gate required uint32 delivery_gate = 11; + repeated UnconfirmedDelivery unconfirmed_deliveries_cyan = 12; + repeated UnconfirmedDelivery unconfirmed_deliveries_magenta = 13; } message OrderInfo { @@ -103,20 +115,6 @@ message SetOrderDelivered { required uint32 order_id = 2; } -message UnconfirmedDelivery { - enum CompType { - COMP_ID = 2000; - MSG_TYPE = 45; - } - - required uint32 id = 1; - required Team team_color = 2; - required uint32 order_id = 3; - required uint32 gate = 4; - required Time delivery_time = 5; -} - - message ConfirmDelivery { enum CompType { COMP_ID = 2000; From 451d9c2f48797b150c669e731380c1e3d51d8237 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 14 Feb 2019 11:59:01 +0100 Subject: [PATCH 49/54] rcll: send unconfirmed deliveries as part of the OrderInfo Instead of sending each unconfirmed delivery separately, send the list of all currently unconfirmed deliveries as part of the OrderInfo. --- src/games/rcll/net.clp | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/games/rcll/net.clp b/src/games/rcll/net.clp index 343d10fd5..9e0469080 100644 --- a/src/games/rcll/net.clp +++ b/src/games/rcll/net.clp @@ -197,28 +197,6 @@ (pb-destroy ?attmsg) ) -(defrule send-delivery-msg - ?pd <- (product-delivered (id ?id) (team ?team) (order ?order) - (game-time ?time) (confirmed FALSE) - (delivery-gate ?gate)) - => - (bind ?msg (pb-create "llsf_msgs.UnconfirmedDelivery")) - (pb-set-field ?msg "id" ?id) - (pb-set-field ?msg "team_color" ?team) - (pb-set-field ?msg "order_id" ?order) - (pb-set-field ?msg "gate" ?gate) - (bind ?delivery-time (pb-field-value ?msg "delivery_time")) - (if (eq (type ?delivery-time) EXTERNAL-ADDRESS) then - (bind ?gt (time-from-sec ?time)) - (pb-set-field ?delivery-time "sec" (nth$ 1 ?gt)) - (pb-set-field ?delivery-time "nsec" (integer (* (nth$ 2 ?gt) 1000))) - (pb-set-field ?msg "delivery_time" ?delivery-time) ; destroys ?delivery-time! - ) - (do-for-all-facts ((?client network-client)) (not ?client:is-slave) - (pb-send ?client:id ?msg)) - (pb-destroy ?msg) -) - (defrule net-recv-SetGameState ?sf <- (gamestate (state ?state)) ?mf <- (protobuf-msg (type "llsf_msgs.SetGameState") (ptr ?p) (rcvd-via STREAM)) @@ -603,6 +581,18 @@ (pb-destroy ?s) ) +(deffunction net-create-UnconfirmedDelivery (?id ?time) + (bind ?msg (pb-create "llsf_msgs.UnconfirmedDelivery")) + (pb-set-field ?msg "id" ?id) + (bind ?delivery-time (pb-field-value ?msg "delivery_time")) + (if (eq (type ?delivery-time) EXTERNAL-ADDRESS) then + (bind ?gt (time-from-sec ?time)) + (pb-set-field ?delivery-time "sec" (nth$ 1 ?gt)) + (pb-set-field ?delivery-time "nsec" (integer (* (nth$ 2 ?gt) 1000))) + (pb-set-field ?msg "delivery_time" ?delivery-time) ; destroys ?delivery-time! + ) + (return ?msg) +) (deffunction net-create-Order (?order-fact) (bind ?o (pb-create "llsf_msgs.Order")) @@ -625,7 +615,17 @@ (nth$ 1 (fact-slot-value ?order-fact delivery-period))) (pb-set-field ?o "delivery_period_end" (nth$ 2 (fact-slot-value ?order-fact delivery-period))) - + (do-for-all-facts + ((?delivery product-delivered)) + (eq ?delivery:confirmed FALSE) + (bind ?d (net-create-UnconfirmedDelivery ?delivery:id ?delivery:game-time)) + (switch ?delivery:team + (case CYAN then + (pb-add-list ?o "unconfirmed_deliveres_cyan" ?d) + ) + (case MAGENTA then + (pb-add-list ?o "unconfirmed_deliveres_magenta" ?d) + ) (return ?o) ) From 067cc1ebd7b4d6f67ecf0e32524010f45111749e Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 14 Feb 2019 12:22:53 +0100 Subject: [PATCH 50/54] msgs: only keep one list of unconfirmed deliveries Instead of keeping one repeated field for each team, only use one field for both and denote the team in the sub-message. --- src/msgs/OrderInfo.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/msgs/OrderInfo.proto b/src/msgs/OrderInfo.proto index ac81d1185..9df7507ac 100644 --- a/src/msgs/OrderInfo.proto +++ b/src/msgs/OrderInfo.proto @@ -52,7 +52,8 @@ message UnconfirmedDelivery { } required uint32 id = 1; - required Time delivery_time = 2; + required Team team = 2; + required Time delivery_time = 3; } message Order { @@ -91,8 +92,7 @@ message Order { // (non-defunct, i.e. non-red light) gate required uint32 delivery_gate = 11; - repeated UnconfirmedDelivery unconfirmed_deliveries_cyan = 12; - repeated UnconfirmedDelivery unconfirmed_deliveries_magenta = 13; + repeated UnconfirmedDelivery unconfirmed_deliveries = 12; } message OrderInfo { From 2e20967e9803c596375e2674afda69981604867a Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 14 Feb 2019 15:02:36 +0100 Subject: [PATCH 51/54] shell: use nested unconfirmed deliveries from OrderInfo Adapt the shell to read the unconfirmed deliveries from the OrderInfo instead of receiving and maintaining them separately. --- src/shell/menus.cpp | 70 +++++++++++++++++++++++---------------------- src/shell/menus.h | 27 ++++++++--------- src/shell/shell.cpp | 28 ++---------------- src/shell/shell.h | 2 -- 4 files changed, 50 insertions(+), 77 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 80e61fe45..8c9b67b76 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -539,34 +539,32 @@ RobotMaintenanceMenu::det_cols(std::shared_ptr &rinfo) OrderDeliverMenu::OrderDeliverMenu (NCursesWindow *parent, llsf_msgs::Team team, - std::vector> deliveries, std::shared_ptr oinfo, std::shared_ptr gstate) - : Menu(det_lines(team, deliveries) + 1 + 2 + 1, 25 + 2, - (parent->lines() - (det_lines(team, deliveries) + 1))/2, + : Menu(det_lines(team, oinfo) + 1 + 2 + 1, 25 + 2, + (parent->lines() - (det_lines(team, oinfo) + 1))/2, (parent->cols() - 26)/2), - oinfo_(oinfo), deliveries_(deliveries), team_(team) + oinfo_(oinfo), team_(team) { delivery_selected_ = false; - int n_items = det_lines(team, deliveries); + show_all_selected_ = false; + int n_items = det_lines(team, oinfo); items_.resize(n_items); int ni = 0; NCursesMenuItem **mitems = new NCursesMenuItem*[3 + n_items]; - for (auto && delivery : deliveries) { - if (delivery->team_color() != team) { continue; } - int min = delivery->delivery_time().sec() / 60; - int sec = delivery->delivery_time().sec() - min * 60; - std::string s; - for (int j = 0; j < oinfo->orders_size(); ++j) { - const llsf_msgs::Order &o = oinfo->orders(j); - if (o.id() == delivery->order_id()) { - s = boost::str(boost::format("%2u: %2s %02u:%02u") - % o.id() - % llsf_msgs::Order::Complexity_Name(o.complexity()) - % min % sec); - items_[ni++] = std::make_tuple(delivery->id(), delivery->order_id(), s); - break; - } + for (int i = 0; i < oinfo->orders_size(); ++i) { + const llsf_msgs::Order &order = oinfo->orders(i); + for (int j = 0; j < order.unconfirmed_deliveries_size(); j++) { + const llsf_msgs::UnconfirmedDelivery &delivery = order.unconfirmed_deliveries(j); + if (delivery.team() != team) { continue; } + int min = delivery.delivery_time().sec() / 60; + int sec = delivery.delivery_time().sec() - min * 60; + std::string s; + s = boost::str(boost::format("%2u: %2s %02u:%02u") + % order.id() + % llsf_msgs::Order::Complexity_Name(order.complexity()) + % min % sec); + items_[ni++] = std::make_tuple(delivery.id(), order.id(), s); } } std::sort(items_.begin(), items_.end()); @@ -605,15 +603,10 @@ OrderDeliverMenu::delivery_selected(int i) delivery_idx_ = i; } -std::shared_ptr +unsigned int OrderDeliverMenu::delivery() const { - auto delivery = std::find_if(deliveries_.begin(), - deliveries_.end(), - [this](std::shared_ptr delivery) { - return delivery->id() == delivery_idx_; - }); - return *delivery; + return delivery_idx_; } bool @@ -702,12 +695,14 @@ OrderDeliverMenu::On_Menu_Init() int OrderDeliverMenu::det_lines(llsf_msgs::Team team, - std::vector> &deliveries) + std::shared_ptr &order_info) { int lines = 0; - for (auto && delivery : deliveries) { - if (delivery->team_color() == team) { - lines++; + for (int i = 0; i < order_info->orders_size(); i++) { + for (int j = 0; j < order_info->orders(i).unconfirmed_deliveries_size(); j++) { + if (order_info->orders(i).unconfirmed_deliveries(j).team() == team) { + lines++; + } } } return lines; @@ -873,10 +868,10 @@ SelectOrderByIDMenu::operator bool() const DeliveryCorrectMenu::DeliveryCorrectMenu(NCursesWindow * parent, llsf_msgs::Team team, - std::shared_ptr delivery, + unsigned int delivery, std::shared_ptr oinfo) : Menu(5, 25 + 2, (parent->lines() - 2) / 2, (parent->cols() - 26) / 2), - delivery_(delivery), + delivery_id_(delivery), correct_(false), correct_selected_(false), oinfo_(oinfo), @@ -920,7 +915,14 @@ DeliveryCorrectMenu::On_Menu_Init() auto order_p = std::find_if(oinfo_->orders().begin(), oinfo_->orders().end(), - [this](const llsf_msgs::Order &o) { return o.id() == delivery_->order_id(); }); + [this](const llsf_msgs::Order &o) { + for (int i = 0; i < o.unconfirmed_deliveries_size(); i++) { + if (o.unconfirmed_deliveries(i).id() == delivery_id_) { + return true; + } + } + return false; + }); if (order_p == oinfo_->orders().end()) { printw(1, 14, "UNKNOWN"); refresh(); diff --git a/src/shell/menus.h b/src/shell/menus.h index 1149e67e7..86f7957db 100644 --- a/src/shell/menus.h +++ b/src/shell/menus.h @@ -205,24 +205,21 @@ class OrderDeliverMenu : public Menu { public: OrderDeliverMenu(NCursesWindow *parent, llsf_msgs::Team team, - std::vector> deliveries, std::shared_ptr oinfo, std::shared_ptr gstate); - std::shared_ptr delivery() const; + unsigned int delivery() const; bool show_all() const; operator bool() const; private: virtual void On_Menu_Init(); - int det_lines(llsf_msgs::Team team, - std::vector> &deliveries); - void show_all_selected(); + int det_lines(llsf_msgs::Team team, std::shared_ptr &order_info); + void show_all_selected(); void delivery_selected(int i); private: std::shared_ptr oinfo_; - std::vector> deliveries_; llsf_msgs::Team team_; bool show_all_selected_; bool delivery_selected_; @@ -264,7 +261,7 @@ class DeliveryCorrectMenu : public Menu public: DeliveryCorrectMenu(NCursesWindow * parent, llsf_msgs::Team team, - std::shared_ptr delivery, + unsigned int delivery, std::shared_ptr oinfo); bool correct() const; @@ -275,14 +272,14 @@ class DeliveryCorrectMenu : public Menu void correct_selected(bool); private: - std::shared_ptr delivery_; - bool correct_; - bool correct_selected_; - std::shared_ptr oinfo_; - llsf_msgs::Team team_; - std::string s_yes_; - std::string s_no_; - std::string s_cancel_; + unsigned int delivery_id_; + bool correct_; + bool correct_selected_; + std::shared_ptr oinfo_; + llsf_msgs::Team team_; + std::string s_yes_; + std::string s_no_; + std::string s_cancel_; }; diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 37c166ed2..9ba7210b1 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -327,7 +327,7 @@ LLSFRefBoxShell::handle_keyboard(const boost::system::error_code& error) tcsm(); if (tcsm) { OrderDeliverMenu odm( - panel_, tcsm.get_team_color(), unconfirmed_deliveries_, last_orderinfo_, last_game_state_); + panel_, tcsm.get_team_color(), last_orderinfo_, last_game_state_); odm(); if (odm) { if (odm.show_all()) { @@ -340,7 +340,7 @@ LLSFRefBoxShell::handle_keyboard(const boost::system::error_code& error) } else { DeliveryCorrectMenu dcm(panel_, tcsm.get_team_color(), odm.delivery(), last_orderinfo_); dcm(); - if (dcm) { send_confirm_delivery(odm.delivery()->id(), dcm.correct()); } + if (dcm) { send_confirm_delivery(odm.delivery(), dcm.correct()); } } } } @@ -509,12 +509,6 @@ LLSFRefBoxShell::send_robot_maintenance(llsf_msgs::Team team, void LLSFRefBoxShell::send_confirm_delivery(unsigned int delivery_id, bool correct) { - unconfirmed_deliveries_.erase( - std::find_if(std::begin(unconfirmed_deliveries_), - std::end(unconfirmed_deliveries_), - [delivery_id](const std::shared_ptr delivery) { - return delivery->id() == delivery_id; - })); llsf_msgs::ConfirmDelivery od; od.set_delivery_id(delivery_id); od.set_correct(correct); @@ -838,23 +832,6 @@ LLSFRefBoxShell::client_msg(uint16_t comp_id, uint16_t msg_type, } } - std::shared_ptr delivery; - if ((delivery = std::dynamic_pointer_cast(msg))) { - bool duplicate = false; - for (auto && existing_delivery : unconfirmed_deliveries_) { - if (existing_delivery->id() == delivery->id()) { - duplicate = true; - break; - } - } - if (!duplicate) { - unconfirmed_deliveries_.push_back(delivery); - logf("New unconfirmed delivery by %s for order %u", - llsf_msgs::Team_Name(delivery->team_color()).c_str(), - delivery->order_id()); - } - } - std::shared_ptr lm; if ((lm = std::dynamic_pointer_cast(msg))) { log(lm->log_level(), lm->ts_sec(), lm->ts_nsec(), lm->component(), lm->message()); @@ -1186,7 +1163,6 @@ LLSFRefBoxShell::run() message_register.add_message_type(); message_register.add_message_type(); message_register.add_message_type(); - message_register.add_message_type(); client->signal_connected().connect( boost::bind(&LLSFRefBoxShell::dispatch_client_connected, this)); diff --git a/src/shell/shell.h b/src/shell/shell.h index d0b8eae1f..52da57ab3 100644 --- a/src/shell/shell.h +++ b/src/shell/shell.h @@ -168,8 +168,6 @@ class LLSFRefBoxShell std::vector robots_; std::map machines_; std::vector orders_; - std::vector> - unconfirmed_deliveries_; boost::asio::io_service io_service_; boost::asio::deadline_timer timer_; From 2429c3d48ff7bc198b20a6f58a7aaf6af7bef5e8 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 14 Feb 2019 15:05:45 +0100 Subject: [PATCH 52/54] rcll: only create a single list of unconfirmed deliveries The message format has been changed to only keep a single list of unconfirmed deliveries, adapt accordingly. --- src/games/rcll/net.clp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/games/rcll/net.clp b/src/games/rcll/net.clp index 9e0469080..cb93a3f85 100644 --- a/src/games/rcll/net.clp +++ b/src/games/rcll/net.clp @@ -581,9 +581,10 @@ (pb-destroy ?s) ) -(deffunction net-create-UnconfirmedDelivery (?id ?time) +(deffunction net-create-UnconfirmedDelivery (?id ?team ?time) (bind ?msg (pb-create "llsf_msgs.UnconfirmedDelivery")) (pb-set-field ?msg "id" ?id) + (pb-set-field ?msg "team" ?team) (bind ?delivery-time (pb-field-value ?msg "delivery_time")) (if (eq (type ?delivery-time) EXTERNAL-ADDRESS) then (bind ?gt (time-from-sec ?time)) @@ -617,15 +618,10 @@ (nth$ 2 (fact-slot-value ?order-fact delivery-period))) (do-for-all-facts ((?delivery product-delivered)) - (eq ?delivery:confirmed FALSE) - (bind ?d (net-create-UnconfirmedDelivery ?delivery:id ?delivery:game-time)) - (switch ?delivery:team - (case CYAN then - (pb-add-list ?o "unconfirmed_deliveres_cyan" ?d) - ) - (case MAGENTA then - (pb-add-list ?o "unconfirmed_deliveres_magenta" ?d) - ) + (and (eq ?delivery:confirmed FALSE) (eq ?delivery:order (fact-slot-value ?order-fact id))) + (bind ?d (net-create-UnconfirmedDelivery ?delivery:id ?delivery:team ?delivery:game-time)) + (pb-add-list ?o "unconfirmed_deliveries" ?d) + ) (return ?o) ) From 691d1f05edc1db33b264e14662736021dc0cda49 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Thu, 14 Feb 2019 15:14:17 +0100 Subject: [PATCH 53/54] shell: fix position and width of OrderDeliverMenu --- src/shell/menus.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shell/menus.cpp b/src/shell/menus.cpp index 8c9b67b76..c8162c57d 100644 --- a/src/shell/menus.cpp +++ b/src/shell/menus.cpp @@ -541,9 +541,9 @@ OrderDeliverMenu::OrderDeliverMenu (NCursesWindow *parent, llsf_msgs::Team team, std::shared_ptr oinfo, std::shared_ptr gstate) - : Menu(det_lines(team, oinfo) + 1 + 2 + 1, 25 + 2, - (parent->lines() - (det_lines(team, oinfo) + 1))/2, - (parent->cols() - 26)/2), + : Menu(det_lines(team, oinfo) + 2 + 2, 18 + 2, + (parent->lines() - (det_lines(team, oinfo) + 2))/2, + (parent->cols() - 18)/2), oinfo_(oinfo), team_(team) { delivery_selected_ = false; From 055c72aacf27ba5cb946e6665684ce9138560c18 Mon Sep 17 00:00:00 2001 From: Till Hofmann Date: Tue, 9 Apr 2019 16:15:58 +0200 Subject: [PATCH 54/54] rcll: improve readability of do-for-all-facts in net-create-Order Co-authored-by: Tim Niemueller --- src/games/rcll/net.clp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/games/rcll/net.clp b/src/games/rcll/net.clp index cb93a3f85..40757aa3a 100644 --- a/src/games/rcll/net.clp +++ b/src/games/rcll/net.clp @@ -616,9 +616,11 @@ (nth$ 1 (fact-slot-value ?order-fact delivery-period))) (pb-set-field ?o "delivery_period_end" (nth$ 2 (fact-slot-value ?order-fact delivery-period))) + (do-for-all-facts ((?delivery product-delivered)) (and (eq ?delivery:confirmed FALSE) (eq ?delivery:order (fact-slot-value ?order-fact id))) + (bind ?d (net-create-UnconfirmedDelivery ?delivery:id ?delivery:team ?delivery:game-time)) (pb-add-list ?o "unconfirmed_deliveries" ?d) )