javaFX代写: COMP3004

‘Simple’ AI strategies (under abstract class AbstractAI)

You DO have to use the strategy pattern AND need to avoid code redundancy. You do NOT need to encode any other strategy for Iteration 1: more complex ones will be given for Iteration 2.

ALL strategies MUST follow the interface we are defining below.
This interface is NOT necessarily complete. That is, you may have to introduce procedures (e.g., for setting up a quest, for playing a stage of a quest, etc.)
In other words, you CAN add polymorphic procedures to the abstract strategy IF necessary. Concrete strategies can also have their own specific procedures, WHICH THE GAME CANNOT USE. The game can only refer to the abstract polymorphic procedures of the AbstractAI class.

(If you find what you think are errors, please email me urgently.)
Do NOT attempt Strategy1 before having Strategy 2 working polymorphically.

1) Deciding on participating in tournaments

procedure doIParticipateInTournament

Strategy 1:
Can any player including myself win/evolve by winning this tournament? If so: I announce I participate
Else I do not participate

To decide what to play:
If another player who can win/evolve by winning this tournament does participate OR If I can win/evolve myself

Then: I play the strongest possible hand (including amour and allies) Else: I play only weapons I have two or more instances of

Strategy 2:
I announce I participate.

To decide what to play:
I play as few cards to get 50 or my best possible Battle points

2) Deciding on sponsoring or not a quest

procedure DoISponsorAQuest

Strategy 1:
If someone else could win/evolve by winning this quest
THEN I do not sponsor
ELSE IF I have a sufficient number of valid foes (ie with increasing battle points) taking into consideration having a test reduces this number by 1.

THEN SPONSOR AND SETUP1 ELSE I decline sponsoring

SETUP 1:

  • –  set up last stage to be at least 50
  • –  set up second last stage to be a test if possible
  • –  going backwards towards the first stage, set up previous stage to be

    strongest foe with any one weapon of which I have two or more instances while respecting a valid order of battle points

    Strategy 2:
    If someone else could win/evolve by winning this quest
    THEN I do not sponsor
    ELSE IF I have a sufficient number of valid foes (ie with increasing battle points) taking into consideration having a test reduces this number by 1.

    THEN SPONSOR AND SETUP2 ELSE decline sponsoring

    SETUP2:

  • –  set up last stage to be at least 40
  • –  set up second last stage to be a test if possible
  • –  set up previous stages from first to second last non-test stage, in increasing

    order, to use my weakest foes and no weapons

3) Deciding on participating in a quest

procedure doIParticipateInQuest

NB: you DO NOT have to play anything for a stage if you think you’re going to lose in any case or if you think you are already strong enough.
NB: you can play only 1 amour per quest (and lose it afterwards)

Strategy 1: IF

C1 I have 2 weapons/allies per stage AND
C2: I have at least 2 foes of less than 20 points (to discard for a test)

THEN participate and play1 ELSE I do not participate

Play1:
– if a test, see4) and 5) – else

a) sort available allies/amour/weapons in decreasing order of BPs b) if last stage: play strongest valid combination

else if you have 1 or 2 allies/amour to play, play them c) if you have not played 2 cards in b),

then play weakest weapon(s) in order to have played 2 cards else do not play more cards

Strategy 2: IF

C1 I can increment by 10 at each stage AND
C2: I have at least 2 foes of less than 25 points (to discard for a test)

THEN participate and play2 ELSE I do not participate

Play2:
– if a test, see4) and 5) – else if last stage

then play strongest valid combination
else play an increment of +10 using amour first, then ally, then weapon(s)

4) Deciding on how much to bid in a test

procedure nextBid

(Remember that NO player is allowed to bid more than the number of cards in hand.)

Strategy 1:
Bid once and only once.
If valid (ie increase over current bid), then bid the number of foes of less than 20 points you have in your hand (using lowest value of foes)

Strategy 2:
first round: If valid (ie increase over current bid), then bid the number of foes of less than 25 points you have in your hand

second round: If valid (ie increase over current bid), then bid the number of foes of less than 25 points you have in your hand + number of duplicates

5) Deciding on which cards to discard if a test is won

procedure discardAfterWinningTest

Strategy 1:
Discard foes of less than 20 points you have in your hand

Strategy 2:
If first round: Discard foes of less than 25 points you have in your hand

If second round: discard foes of round 1 and all duplicates