-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
81 lines (67 loc) · 2.35 KB
/
Program.fs
File metadata and controls
81 lines (67 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
open Initialization
open LocalSearch.Play
open LocalSearch.Scoring.Scorers
open LocalSearch.Scoring.CompositeEvaluators
open Game
open RuntimeBenchmark
open SearchTree
open Test
open Writer
open System
let usage = @"
Usage: dotnet run [keyword] [lookahead depth] [trials].
Keywords:
ABPrunedMinimaxMaximumScore will play 2048 using an alpha-beta pruned minimax search, using the ingame scores of states.
ExpectimaxMaximumScore will play 2048 25 times using an expectimax search that uses ingame scores
ExpectimaxEUMR will play 2048 using expectimax search and a multistage heuristic to evaluate states
Lookahead depth is the depth of search trees generated when calculating the next move. Must be >=2. 2 is the most well-tested. 3 and above run slowly.
Trials is the number of games the program will run back to back. Only the highest-scoring game will be printed to console. Must be >=1.
To run unit tests: dotnet run test
"
let printUsage () =
usage
|> writeStringToConsole
let tests () =
testBasicShifts
testOrderMatters
testOrderMatters2
testPackedBoard
testRightUp
testUp2
testUnlikePacked
testMilestone1SampleFirstMove
testMilestone1SampleSecondMove
let tileInsertionOptions = [Exponent 1; Exponent 2]
let playExpectimax = playTrialsWithExhaustiveSearch tileInsertionOptions
let playAlphaBeta = playTrialsWithAlphaBetaPruning tileInsertionOptions
let initialTileOptions = [Exponent 1]
let initialState =
makeInitialBoard 4 4 2 initialTileOptions
|> SearchTree.toSearchTreeRoot
let commandSwitch args =
match args with
| [|"test"|] ->
tests ()
| [|"ExpectimaxMaximumScore"; lookaheads; trials|] ->
initialState
|> playExpectimax (int lookaheads) chooseByBestScoreExpectation (int trials)
||> writeResult
| [|"ExpectimaxEUMR"; lookaheads; trials|] ->
initialState
|> playExpectimax (int lookaheads) chooseByEUMR (int trials)
||> writeResult
| [|"ABPrunedMaximumScore"; lookaheads; trials|] ->
initialState
|> playAlphaBeta (int lookaheads) scoreByScore (int trials)
||> writeResult
| _ ->
printUsage ()
[<EntryPoint>]
let main args =
try
(commandSwitch, args) ||> measureAndPrintRuntime
with
| :? FormatException as fe ->
"Error: " + fe.Message |> printfn "%s"
printUsage ()
0