Player47.adb

Eftersom spelaren kan byggas i några olika lägen, ett för att spela med och att för att använda då spelaren lär sig att spela (med vår egen spelledare) finns det rader som
--{LEARN
och
--}
Dessa meddelar vilka delar som hör till endast ett läge.
function Player47 (MoveNum : Integer;
                   OppName : PlayerNameType;
                   OppLast : Move;
                   --{FINISH_THEM--{COMBAT
                   OppScore, MyScore : Integer) return Move is
                   --}--{LEARN
                   OppScore, MyScore : Integer;
                   ForceMethod : Integer) return Move is
                   --}
   DoMove : Move;
begin
   MN := MoveNum;
   ON := OppName;
   OL := OppLast;
   OS := OppScore;
   MS := MyScore;

   if MoveNum = 1 and TotalNofMovesThisMatch /= 0 then
      TotalNofMoves := TotalNofMovesThisMatch;
   end if;
   TotalNofMovesThisMatch := MoveNum;

   if MoveNum > 1 then
      OppMoves(MoveNum-1) := OppLast;
   end if;

   if MoveNum > TotalNofMoves-1 then
      return Defect;
   end if;

   --{FINISH_THEM--{COMBAT
   if MoveNum = 1 then -- new game started, reinitialize
      UseTactics := 0;
      CurrentOpponent := OpponentSpecs'Last;
      while CurrentOpponent >= OpponentSpecs'First
      loop
         exit when OpponentSpecs(CurrentOpponent).Name = OppName;
         CurrentOpponent := CurrentOpponent - 1;
      end loop;
      if CurrentOpponent /= 0 then
         if OpponentSpecs(CurrentOpponent).MatchNum < 2 then
            OpponentSpecs(CurrentOpponent).MatchNum := OpponentSpecs(CurrentOpponent).MatchNum + 1;
         end if;
         UseTactics := OpponentSpecs(CurrentOpponent).Tactics(OpponentSpecs(CurrentOpponent).MatchNum);
         if UseTactics = -1 then
            CurrentMoveSpecs := MoveSpecs'Last;
            while CurrentMoveSpecs >= MoveSpecs'First
            loop
               exit when MoveSpecs(CurrentMoveSpecs).Name = OppName;
               CurrentMoveSpecs := CurrentMoveSpecs - 1;
            end loop;
            if (CurrentMoveSpecs < MoveSpecs'First) then
              UseTactics := 0;
            end if;
         end if;
      end if;
      if TotalNofMoves < 20 then UseTactics:=0; end if;
   elsif MoveNum = 21 and UseTactics /= 0 then
      if MyScore < OpponentSpecs(CurrentOpponent).Expect(OpponentSpecs(CurrentOpponent).MatchNum).Player1 or
        OppScore > OpponentSpecs(CurrentOpponent).Expect(OpponentSpecs(CurrentOpponent).MatchNum).Player2 then
         OpponentSpecs(CurrentOpponent).Tactics(2) := 0;
         UseTactics := 0;
         CurrentOpponent := 0;
         MyMoves(MoveNum) := Cooperate; -- try to start a friendly game
         return Cooperate;
      end if;
   elsif MoveNum > 25 and then (MyScore < MoveNum/2 or MyScore < -5) and then CurrentOpponent /= 0 then
      OpponentSpecs(CurrentOpponent).Tactics(2) := 0;
      UseTactics := 0;
      CurrentOpponent := 0;
      MyMoves(MoveNum) := Cooperate; -- try to start a friendly game
      return Cooperate;
   end if;
   --}--{LEARN
   UseTactics := ForceMethod;
   --}

   case UseTactics is
      when  1 => DoMove := Default;
      when  2 => DoMove := TitForTat;
      when  3 => DoMove := HandleTitForTat;
      when  4 => DoMove := InverseTitForTat;
      when  5 => DoMove := Pattern1;
      when  6 => DoMove := Pattern2;
      when  7 => DoMove := Logic1;
      when  8 => DoMove := Logic2;
      when  9 => DoMove := Logic3;
      when 10 => DoMove := TitFor2Tat1; -- need 2 defect to defect
      when 11 => DoMove := TitFor2Tat2; -- need 2 similar to change action
      when 12 => DoMove := DefWhen2;
      when 13 => DoMove := DefWhen5;
      when 14 => DoMove := DefWhen8;
      when 15 => DoMove := AlwaysCooperate;
      when 16 => DoMove := AlwaysDefect;
      when 17 => DoMove := InSomeOrder;
      when 18 => DoMove := CrazyPlayer;
      when 19 => DoMove := CrazyPlayer2;
      when -1 => DoMove := PredefPattern;
      --{LEARN
      when others => null;
      --}--{FINISH_THEM--{COMBAT
      when others => DoMove := Default;
      --}
   end case;

   MyMoves(MoveNum) := DoMove;

   return DoMove;
end Player47;

Tillbaka till huvudsidan