mirror of
https://github.com/TwoFX/Morris.git
synced 2026-02-04 13:02:52 +00:00
Add controller, external assembly loading and other fancy things
This commit is contained in:
28
ExternalBotTest/FSharpRandomBot.fs
Normal file
28
ExternalBotTest/FSharpRandomBot.fs
Normal file
@@ -0,0 +1,28 @@
|
||||
(*
|
||||
* 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
|
||||
Reference in New Issue
Block a user