Message text This is how I'd do it. I've spent some time on it so I hope it helps. It's also very detailed, I hope I have made no mistakes and explained everything clearly!
This is a worst-case optimisation, good when there are a lot of ships close together. It should be able to handle ALL the cases.
the idea is to start with the STRONGER SHIPS (those that are advancing, are heavy, and have an expert crew...)
To check for loops, there are a few counters. When the procedure is repeated enough times, this means there are loops. At that point all "conflicts" should have been resolved.
------------------------------------------------
Notice that:
I don't know how the "FOUL" table works, so I've neglected this aspect. It may add some time to the procedure, since I'm exploiting the fact that a strong ship doesn't care about weak ships when trying to advance!
In fact, I'm not checking all conflicts, only those with ships that are stronger or equal!
################################################
(A) order the ships in "move strength", that is (schematically)
(A.1) grappled ships (A.2) ships not moving (A.3.i) ships advancing, heavy, with good crew (A.3.ii) ships advancing, heavy, with poor crew (A.3.iii) ships advancing, light, with good crew (A.3.iv) ships advancing, light, with poor crew (A.4.i) ships turning, heavy, with good crew (A.4.ii) ships turning, heavy, with poor crew (A.4.iii) ships turning, light, with good crew (A.4.iv) ships turning, light, with poor crew
easy way to do this is: a ship starts with strength 0.
add 40000 if grappled/not moving add 30000 if advancing add 10000 if turning add 100 * weight add 1 * crew quality
then sort the list
------------------------------------------------
(B) mark the hexes as follows:
(B.1) all hexes are "FREE" unless (see below) (B.2) "OCCUPIED" (these cannot be entered in any case): (B.2.i) both hexes occupied by immobile ships (A.1), (A.2) (B.2.ii) the forward hex of advancing ships (A.3) (B.2.iii) the forward hex of turning ships (A.4) (B.3) "MAYBE FREE"(these might be enterable, see below) (B.3.i) the back hex of advancing ships (A.3) (B.3.ii) the back hex of turning ships (A.3)
% note that steps (A) and (B) should be handled together by the programme, % I have separated these only for clarity.
=====================================================
REPEAT PROCEDURES (C--F) four times (once per step)
-----------------------------------------------------
(C.1) initialise a counter "MOVED SHIPS" starting at the number of ships in play (C.2) initialise a counter "LOOPS DONE" at zero
-----------------------------------------------------
(D) Move the first ship in the list generated in step A. All ships are "ACTIVE" (or "FOULED") at the start. One or more may become "WAITING" if they are trying to enter a "MAYBE FREE" hex (see below). A ship that succesfully moves will become "MOVED". The first "ACTIVE" ship must be moved now!
(D.1) if ship is grappled/immobile: "MOVED SHIPS"++. change the ship status from "ACTIVE" to "MoVED"
(D.2.i) if she's trying to move to an "OCCUPIED" hex she stops: "MOVED SHIPS"++. change the ship status from "ACTIVE" to "MoVED" change her back hex from "MAYBE FREE" to "OCCUPIED"
(D.2.ii) if she's trying to move to a "FREE" hex:
(D.2.ii.a) if the next ship in list (A) is weaker, advance the ship: "MOVED SHIPS"++. change the ship status from "ACTIVE" to "MoVED" change her back hex from "MAYBE FREE" to "FREE" change the hex she's moved into from "FREE" to OCCUPIED
(D.2.ii.b) if there are one or more ships that have the same strength in list (A), but there are no conflicts, advance the ship. "MOVED SHIPS"++. change the ship status from "ACTIVE" to "MoVED" change her back hex from "MAYBE FREE" to "FREE" change the hex she's moved into from "FREE" to OCCUPIED
(D.2.ii.c) if there are one or more ships that have the same strength in list (A), and there are conflicts, choose one ship at random. She advances. The other ones stop. "MOVED SHIPS"++(number of conflicting ships). change all ships status from "ACTIVE" to "MoVED" change winning ship's back hex from "MAYBE FREE" to "FREE" change winning ship's new hex from "FREE" to OCCUPIED change losing ships' back hexes from "MAYBE FREE" to "OCCUPIED"
(D.2.iii) if she's trying to move to a "MAYBE FREE" hex:
(D.2.iii.a) if there are stronger ships in list (A) that are WAITING (see below), check if they want to go to the same hex. If they want to, the current ship stops "MOVED SHIPS"++. change losing ship's status from "ACTIVE" to "MoVED" change losing ship's back hex from "MAYBE FREE" to "OCCUPIED"
(D.2.iii.b) if the next ship in list (A) is weaker: change the ship status from "ACTIVE" to "WAITING"
(D.2.iii.c) if there are one or more ships that have the same strength in list (A), but there are no conflicts change the ship status from "ACTIVE" to "WAITING"
(D.2.iii.d) if there are one or more ships that have the same strength in list (A), and there are conflicts, choose one ship at random: Change the winning ship's status from "ACTIVE" to "WAITING" change the losing ships' status from "ACTIVE" to "MoVED" "MOVED SHIPS"++(number of conflicting ships-1) (the -1 is the winning one that is waiting) Change losing ships' back hexes from "MAYBE FREE" to "OCCUPIED"
(D.3.i) If this was the last ship in list go to (E). (D.3.ii) otherwise return to (D).
--------------------------------------------------------
(E.1) "LOOPS DONE"++ (E.2) if "MOVED SHIPS" == "TOTAL SHIPS IN PLAY" the movement phase is over (E.3) if "MOVED SHIPS" < "TOTAL SHIPS IN PLAY" AND "LOOPS DONE" <= "MOVED SHIPS" - "TOTAL SHIPS IN PLAY": mark all "WAITING" ships as "ACTIVE" repeat the procedure (D). (E.4) if "MOVED SHIPS" < "TOTAL SHIPS IN PLAY" AND "LOOPS DONE" > "MOVED SHIPS" - "TOTAL SHIPS IN PLAY": there is a LOOP. Go to procedure (F)
=========================================================
(F) in loops strength does not matter. Notice that all conflicts have been solved at this point!!! You might want to check it during debugging.
(F.1) take the first ship in list, check where she wants to go, check what is occupying that hex. She should be a ship that hasn't moved yet. Add her to the list. (F.2) repeat step (F.1) until you get back to the FIRST ship already on the list: "MOVED SHIPS"++(number of ships in loop) eliminate ships from list (A) move all ships in loop (F.3) if now "MOVED SHIPS" == "TOTAL SHIPS IN PLAY" loop phase is over. otherwise start over from (F.1) |
|
|