mirror of
https://github.com/TwoFX/Morris.git
synced 2025-12-13 08:22:51 +00:00
29 lines
838 B
Forth
29 lines
838 B
Forth
(*
|
|
* FSharpRandomBot.fs
|
|
* Copyright (c) 2016 Markus Himmel
|
|
* This file is distributed under the terms of the MIT license
|
|
*)
|
|
|
|
namespace ExternalBotTest
|
|
|
|
open Morris
|
|
|
|
[<SelectorName("F# KI")>]
|
|
type FSharpRandomBot() =
|
|
|
|
let rng = System.Random ()
|
|
let chooseRandom n = Seq.item (Seq.length n |> rng.Next) n
|
|
|
|
interface IMoveProvider with
|
|
// Funktioniert exakt genauso wie das C#-Pendant
|
|
member this.GetNextMove state =
|
|
let chosen = state.BasicMoves () |> chooseRandom
|
|
|
|
match state.IsValidMove chosen with
|
|
| MoveValidity.ClosesMill ->
|
|
[0..GameState.FIELD_SIZE - 1]
|
|
|> Seq.where (fun d -> int state.Board.[d] = int (state.NextToMove.Opponent()))
|
|
|> chooseRandom
|
|
|> chosen.WithRemove
|
|
| _ -> chosen
|