mentor/derived/MinimaxAlgClass.m3


 Copyright (C) 1995, Digital Equipment Corporation.       
 All rights reserved.                                     
 See the file COPYRIGHT for a full description.           
                                                          
 Last modified on Thu Feb  9 08:48:22 PST 1995 by kalsow  
      modified on Wed Feb 17 16:46:18 PST 1993 by johnh   
      modified on Thu Sep 24 10:59:20 PDT 1992 by mhb     

********************************************************************

      *  NOTE: This file is generated automatically from the event
      *        definition file Minimax.evt.
      ********************************************************************


MODULE MinimaxAlgClass;

<*NOWARN*> IMPORT Rd, ZeusClass, Fmt, TypeFmt, Minimax, Algorithm;
<*NOWARN*> IMPORT Wr, ZeusPanel, FormsVBT, GameBoard, Text, VBT;
<*NOWARN*> IMPORT ZeusUtil;

<* PRAGMA LL *>
Fix any FormsVBT errors; don't handle exceptions for them.
<* FATAL FormsVBT.Error, FormsVBT.Unimplemented *>

REVEAL
  T = Public BRANDED OBJECT
      OVERRIDES
        <* LL = VBT.mu *>
        init := MinimaxDefaultInit;
        snapshot := MinimaxDefaultSnapshot;
        restore := MinimaxDefaultRestore;
        updateEventCounts := MinimaxDefaultUpdateCts;
        feHumanSelection := HumanSelection;
      END;

PROCEDURE MinimaxDefaultInit (v: T): Algorithm.T =
  <* LL = VBT.mu *>
  PROCEDURE Attach (id: TEXT; proc: FormsVBT.Proc) =
    BEGIN
      FormsVBT.AttachProc(v.eventData, id, proc, v);
    END Attach;
  BEGIN
    v.eventData := ZeusPanel.NewForm("MinimaxEventData.fv");
    Attach("stopatCodeEvents", MinimaxDoIt);
    Attach("waitatCodeEvents", MinimaxDoIt);
    Attach("eventCounts", MinimaxRefreshCts);
    Attach("stopAtSetup", MinimaxDoIt);
    Attach("waitAtSetup", MinimaxDoIt);
    Attach("stopAtPlayerMove", MinimaxDoIt);
    Attach("waitAtPlayerMove", MinimaxDoIt);
    Attach("stopAtFinished", MinimaxDoIt);
    Attach("waitAtFinished", MinimaxDoIt);
    Attach("stopAtEvaluateNode", MinimaxDoIt);
    Attach("waitAtEvaluateNode", MinimaxDoIt);
    Attach("stopAtPlayerThinking", MinimaxDoIt);
    Attach("waitAtPlayerThinking", MinimaxDoIt);
    Attach("stopAtFinishedEvalNode", MinimaxDoIt);
    Attach("waitAtFinishedEvalNode", MinimaxDoIt);
    Attach("stopAtBoardValueUpdated", MinimaxDoIt);
    Attach("waitAtBoardValueUpdated", MinimaxDoIt);
    Attach("stopAtHumanCellSelected", MinimaxDoIt);
    Attach("waitAtHumanCellSelected", MinimaxDoIt);
    Attach("stopAtHumanIllegalMove", MinimaxDoIt);
    Attach("waitAtHumanIllegalMove", MinimaxDoIt);
    FromFV (v.eventData, v);    (* Get FV and internal data in sync *)
    RETURN Algorithm.T.init(v);
  END MinimaxDefaultInit;

PROCEDURE MinimaxDoIt (           fv : FormsVBT.T;
                           e  : TEXT;
                           arg: REFANY;
                <*UNUSED*> t  : VBT.TimeStamp) =
  <* LL = VBT.mu *>
  BEGIN
    IF Text.Equal(e, "stopatCodeEvents") THEN
      NARROW(arg, T).stopatCodeEvents :=
          FormsVBT.GetBoolean(fv, "stopatCodeEvents");
    END;
    IF Text.Equal(e, "waitatCodeEvents") THEN
      NARROW(arg, T).waitatCodeEvents :=
          FormsVBT.GetInteger(fv, "waitatCodeEvents");
    END;
    IF Text.Equal(e, "stopAtSetup") THEN
      NARROW(arg, T).eventDataRec.stopAtSetup :=
          FormsVBT.GetBoolean(fv, "stopAtSetup");
    END;
    IF Text.Equal(e, "waitAtSetup") THEN
      NARROW(arg, T).eventDataRec.waitAtSetup :=
          FormsVBT.GetInteger(fv, "waitAtSetup");
    END;
    IF Text.Equal(e, "stopAtPlayerMove") THEN
      NARROW(arg, T).eventDataRec.stopAtPlayerMove :=
          FormsVBT.GetBoolean(fv, "stopAtPlayerMove");
    END;
    IF Text.Equal(e, "waitAtPlayerMove") THEN
      NARROW(arg, T).eventDataRec.waitAtPlayerMove :=
          FormsVBT.GetInteger(fv, "waitAtPlayerMove");
    END;
    IF Text.Equal(e, "stopAtFinished") THEN
      NARROW(arg, T).eventDataRec.stopAtFinished :=
          FormsVBT.GetBoolean(fv, "stopAtFinished");
    END;
    IF Text.Equal(e, "waitAtFinished") THEN
      NARROW(arg, T).eventDataRec.waitAtFinished :=
          FormsVBT.GetInteger(fv, "waitAtFinished");
    END;
    IF Text.Equal(e, "stopAtEvaluateNode") THEN
      NARROW(arg, T).eventDataRec.stopAtEvaluateNode :=
          FormsVBT.GetBoolean(fv, "stopAtEvaluateNode");
    END;
    IF Text.Equal(e, "waitAtEvaluateNode") THEN
      NARROW(arg, T).eventDataRec.waitAtEvaluateNode :=
          FormsVBT.GetInteger(fv, "waitAtEvaluateNode");
    END;
    IF Text.Equal(e, "stopAtPlayerThinking") THEN
      NARROW(arg, T).eventDataRec.stopAtPlayerThinking :=
          FormsVBT.GetBoolean(fv, "stopAtPlayerThinking");
    END;
    IF Text.Equal(e, "waitAtPlayerThinking") THEN
      NARROW(arg, T).eventDataRec.waitAtPlayerThinking :=
          FormsVBT.GetInteger(fv, "waitAtPlayerThinking");
    END;
    IF Text.Equal(e, "stopAtFinishedEvalNode") THEN
      NARROW(arg, T).eventDataRec.stopAtFinishedEvalNode :=
          FormsVBT.GetBoolean(fv, "stopAtFinishedEvalNode");
    END;
    IF Text.Equal(e, "waitAtFinishedEvalNode") THEN
      NARROW(arg, T).eventDataRec.waitAtFinishedEvalNode :=
          FormsVBT.GetInteger(fv, "waitAtFinishedEvalNode");
    END;
    IF Text.Equal(e, "stopAtBoardValueUpdated") THEN
      NARROW(arg, T).eventDataRec.stopAtBoardValueUpdated :=
          FormsVBT.GetBoolean(fv, "stopAtBoardValueUpdated");
    END;
    IF Text.Equal(e, "waitAtBoardValueUpdated") THEN
      NARROW(arg, T).eventDataRec.waitAtBoardValueUpdated :=
          FormsVBT.GetInteger(fv, "waitAtBoardValueUpdated");
    END;
    IF Text.Equal(e, "stopAtHumanCellSelected") THEN
      NARROW(arg, T).eventDataRec.stopAtHumanCellSelected :=
          FormsVBT.GetBoolean(fv, "stopAtHumanCellSelected");
    END;
    IF Text.Equal(e, "waitAtHumanCellSelected") THEN
      NARROW(arg, T).eventDataRec.waitAtHumanCellSelected :=
          FormsVBT.GetInteger(fv, "waitAtHumanCellSelected");
    END;
    IF Text.Equal(e, "stopAtHumanIllegalMove") THEN
      NARROW(arg, T).eventDataRec.stopAtHumanIllegalMove :=
          FormsVBT.GetBoolean(fv, "stopAtHumanIllegalMove");
    END;
    IF Text.Equal(e, "waitAtHumanIllegalMove") THEN
      NARROW(arg, T).eventDataRec.waitAtHumanIllegalMove :=
          FormsVBT.GetInteger(fv, "waitAtHumanIllegalMove");
    END;
  END MinimaxDoIt;

PROCEDURE MinimaxRefreshCts (
                <*UNUSED*> fv  : FormsVBT.T;
                <*UNUSED*> e   : TEXT;
                           arg : REFANY;
                <*UNUSED*> t   : VBT.TimeStamp) =
  <* LL = VBT.mu *>
  BEGIN
    NARROW(arg, T).updateEventCounts(FALSE);
  END MinimaxRefreshCts;

PROCEDURE FromFV (fv : FormsVBT.T; alg: T) =
  <* LL = VBT.mu *>
  BEGIN
    alg.stopatCodeEvents :=
        FormsVBT.GetBoolean(fv, "stopatCodeEvents");
    alg.waitatCodeEvents :=
        FormsVBT.GetInteger(fv, "waitatCodeEvents");
    alg.eventDataRec.stopAtSetup :=
        FormsVBT.GetBoolean(fv, "stopAtSetup");
    alg.eventDataRec.waitAtSetup :=
        FormsVBT.GetInteger(fv, "waitAtSetup");
    alg.eventDataRec.stopAtPlayerMove :=
        FormsVBT.GetBoolean(fv, "stopAtPlayerMove");
    alg.eventDataRec.waitAtPlayerMove :=
        FormsVBT.GetInteger(fv, "waitAtPlayerMove");
    alg.eventDataRec.stopAtFinished :=
        FormsVBT.GetBoolean(fv, "stopAtFinished");
    alg.eventDataRec.waitAtFinished :=
        FormsVBT.GetInteger(fv, "waitAtFinished");
    alg.eventDataRec.stopAtEvaluateNode :=
        FormsVBT.GetBoolean(fv, "stopAtEvaluateNode");
    alg.eventDataRec.waitAtEvaluateNode :=
        FormsVBT.GetInteger(fv, "waitAtEvaluateNode");
    alg.eventDataRec.stopAtPlayerThinking :=
        FormsVBT.GetBoolean(fv, "stopAtPlayerThinking");
    alg.eventDataRec.waitAtPlayerThinking :=
        FormsVBT.GetInteger(fv, "waitAtPlayerThinking");
    alg.eventDataRec.stopAtFinishedEvalNode :=
        FormsVBT.GetBoolean(fv, "stopAtFinishedEvalNode");
    alg.eventDataRec.waitAtFinishedEvalNode :=
        FormsVBT.GetInteger(fv, "waitAtFinishedEvalNode");
    alg.eventDataRec.stopAtBoardValueUpdated :=
        FormsVBT.GetBoolean(fv, "stopAtBoardValueUpdated");
    alg.eventDataRec.waitAtBoardValueUpdated :=
        FormsVBT.GetInteger(fv, "waitAtBoardValueUpdated");
    alg.eventDataRec.stopAtHumanCellSelected :=
        FormsVBT.GetBoolean(fv, "stopAtHumanCellSelected");
    alg.eventDataRec.waitAtHumanCellSelected :=
        FormsVBT.GetInteger(fv, "waitAtHumanCellSelected");
    alg.eventDataRec.stopAtHumanIllegalMove :=
        FormsVBT.GetBoolean(fv, "stopAtHumanIllegalMove");
    alg.eventDataRec.waitAtHumanIllegalMove :=
        FormsVBT.GetInteger(fv, "waitAtHumanIllegalMove");
  END FromFV;

<*UNUSED*>
PROCEDURE ToFV (fv : FormsVBT.T; alg: T) =
  <* LL = VBT.mu *>
  BEGIN
    FormsVBT.PutBoolean(fv, "stopatCodeEvents", alg.stopatCodeEvents);
    FormsVBT.PutInteger(fv, "waitatCodeEvents", alg.waitatCodeEvents);
    FormsVBT.PutBoolean(fv, "stopAtSetup",
                        alg.eventDataRec.stopAtSetup);
    FormsVBT.PutInteger(fv, "waitAtSetup",
                        alg.eventDataRec.waitAtSetup);
    FormsVBT.PutBoolean(fv, "stopAtPlayerMove",
                        alg.eventDataRec.stopAtPlayerMove);
    FormsVBT.PutInteger(fv, "waitAtPlayerMove",
                        alg.eventDataRec.waitAtPlayerMove);
    FormsVBT.PutBoolean(fv, "stopAtFinished",
                        alg.eventDataRec.stopAtFinished);
    FormsVBT.PutInteger(fv, "waitAtFinished",
                        alg.eventDataRec.waitAtFinished);
    FormsVBT.PutBoolean(fv, "stopAtEvaluateNode",
                        alg.eventDataRec.stopAtEvaluateNode);
    FormsVBT.PutInteger(fv, "waitAtEvaluateNode",
                        alg.eventDataRec.waitAtEvaluateNode);
    FormsVBT.PutBoolean(fv, "stopAtPlayerThinking",
                        alg.eventDataRec.stopAtPlayerThinking);
    FormsVBT.PutInteger(fv, "waitAtPlayerThinking",
                        alg.eventDataRec.waitAtPlayerThinking);
    FormsVBT.PutBoolean(fv, "stopAtFinishedEvalNode",
                        alg.eventDataRec.stopAtFinishedEvalNode);
    FormsVBT.PutInteger(fv, "waitAtFinishedEvalNode",
                        alg.eventDataRec.waitAtFinishedEvalNode);
    FormsVBT.PutBoolean(fv, "stopAtBoardValueUpdated",
                        alg.eventDataRec.stopAtBoardValueUpdated);
    FormsVBT.PutInteger(fv, "waitAtBoardValueUpdated",
                        alg.eventDataRec.waitAtBoardValueUpdated);
    FormsVBT.PutBoolean(fv, "stopAtHumanCellSelected",
                        alg.eventDataRec.stopAtHumanCellSelected);
    FormsVBT.PutInteger(fv, "waitAtHumanCellSelected",
                        alg.eventDataRec.waitAtHumanCellSelected);
    FormsVBT.PutBoolean(fv, "stopAtHumanIllegalMove",
                        alg.eventDataRec.stopAtHumanIllegalMove);
    FormsVBT.PutInteger(fv, "waitAtHumanIllegalMove",
                        alg.eventDataRec.waitAtHumanIllegalMove);
    CountsToFV (fv, alg);
  END ToFV;

PROCEDURE CountsToFV (fv : FormsVBT.T; alg: T) =
  <* LL = VBT.mu *>
  BEGIN
    FormsVBT.PutText(fv, "ctOfSetup",
                        Fmt.Int(alg.eventDataRec.ctOfSetup));
    FormsVBT.PutText(fv, "ctOfPlayerMove",
                        Fmt.Int(alg.eventDataRec.ctOfPlayerMove));
    FormsVBT.PutText(fv, "ctOfFinished",
                        Fmt.Int(alg.eventDataRec.ctOfFinished));
    FormsVBT.PutText(fv, "ctOfEvaluateNode",
                        Fmt.Int(alg.eventDataRec.ctOfEvaluateNode));
    FormsVBT.PutText(fv, "ctOfPlayerThinking",
                        Fmt.Int(alg.eventDataRec.ctOfPlayerThinking));
    FormsVBT.PutText(fv, "ctOfFinishedEvalNode",
                        Fmt.Int(alg.eventDataRec.ctOfFinishedEvalNode));
    FormsVBT.PutText(fv, "ctOfBoardValueUpdated",
                        Fmt.Int(alg.eventDataRec.ctOfBoardValueUpdated));
    FormsVBT.PutText(fv, "ctOfHumanCellSelected",
                        Fmt.Int(alg.eventDataRec.ctOfHumanCellSelected));
    FormsVBT.PutText(fv, "ctOfHumanIllegalMove",
                        Fmt.Int(alg.eventDataRec.ctOfHumanIllegalMove));
  END CountsToFV;

PROCEDURE MinimaxDefaultUpdateCts ( v: T; reset: BOOLEAN) =
  <* LL = VBT.mu *>
  BEGIN
    IF reset THEN
      v.eventDataRec.ctOfSetup := 0;
      v.eventDataRec.ctOfPlayerMove := 0;
      v.eventDataRec.ctOfFinished := 0;
      v.eventDataRec.ctOfEvaluateNode := 0;
      v.eventDataRec.ctOfPlayerThinking := 0;
      v.eventDataRec.ctOfFinishedEvalNode := 0;
      v.eventDataRec.ctOfBoardValueUpdated := 0;
      v.eventDataRec.ctOfHumanCellSelected := 0;
      v.eventDataRec.ctOfHumanIllegalMove := 0;
    END;
    CountsToFV (v.eventData, v);
  END MinimaxDefaultUpdateCts;

PROCEDURE MinimaxDefaultSnapshot (v: T; wr: Wr.T)
  RAISES {ZeusClass.Error} =
  <* LL = VBT.mu *>
  BEGIN
    TRY
      Wr.PutChar(wr, '(')
    EXCEPT
    ELSE
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultSnapshot write error");
    END;
    IF v.eventData = NIL THEN
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultSnapshot: " &
          "eventData not set!");
    END;
    TRY
      v.eventData.snapshot(wr)
    EXCEPT
      FormsVBT.Error (msg) =>
        RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultSnapshot FV error: "
          & msg);
    ELSE
      RAISE ZeusClass.Error(
        "MinimaxAlgClass.MinimaxDefaultSnapshot error");
    END;
    Algorithm.T.snapshot(v, wr);
    TRY
      Wr.PutChar(wr, ')')
    EXCEPT
    ELSE
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultSnapshot write error");
    END;
  END MinimaxDefaultSnapshot;

PROCEDURE MinimaxDefaultRestore (v: T; rd: Rd.T)
  RAISES {ZeusClass.Error} =
  <* LL = VBT.mu *>
  BEGIN
    IF rd = NIL THEN RETURN END;
    IF NOT ZeusUtil.EatChar(rd, '(') THEN
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultRestore read error");
    END;
    IF v.eventData = NIL THEN
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultRestore: " &
          "eventData not set!");
    END;
    TRY
      v.eventData.restore(rd);
      v.updateEventCounts(FALSE);
      FromFV(v.eventData, v);
    EXCEPT
    ELSE
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultRestore error");
    END;
    Algorithm.T.restore(v, rd);
    IF NOT ZeusUtil.EatChar(rd, ')') THEN
      RAISE ZeusClass.Error(
          "MinimaxAlgClass.MinimaxDefaultRestore read error");
    END;
  END MinimaxDefaultRestore;

PROCEDURE HumanSelection (self: T
    ; <*UNUSED*> xCoord: INTEGER
    ; <*UNUSED*> yCoord: INTEGER
) =
  <* LL = VBT.mu *>
  BEGIN
    self.evtHandled := FALSE;
  END HumanSelection;

BEGIN
END MinimaxAlgClass.