Seda
Seda

Reputation: 103

Tic Tac Toe implements with min - max method with alfa-beta pruning is there any better solution?

There is a code implements function which assigned every status a value (both parts of min-max method)

Procedure TGraph.Rate(const AState: TState);
Var
i: integer;
Begin //hodnotí stav
if AState.Children.Count > 0 then begin //není list
    if AState.Owner = CComputerPlayer then begin
        // max level
        AState.Rating := AState.Children.Worst.Rating;
    end else begin
        // min level
        AState.Rating := AState.Children.Best.Rating;
    end;
end else begin
    AState.Rating := 0;
    for i := 0 to AState.Fields.Count - 1 do
    begin
        AState.Rating := AState.Rating +
        AState.Fields.FieldsI[i].Rating[AState.Owner];
    end;
    if (AState.Owner = CHumanPlayer) then begin
        AState.Rating := -AState.Rating;
    end;
end;
End;

Upvotes: 0

Views: 336

Answers (1)

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70931

Tic Tac Toe has a finite and quite small space of possible positions. It is not worth it to apply alfa-beta pruning for it. A very simple min-max will work very fast. Also keep in mind if you need to run the algorithm multiple times you can run min-max only once and store the computed results.

Upvotes: 1

Related Questions