-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnim2d.cpp
More file actions
77 lines (70 loc) · 1.54 KB
/
nim2d.cpp
File metadata and controls
77 lines (70 loc) · 1.54 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
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
#include <list.h>
#include "matrix.h"
#include "nimber.h"
#include "hash.h"
/*
* Program to play 2-D Nim.
* July 13, 2005
* Joe Lewis
*/
Nimber newGame(Matrix & game, Hashtable & table, Hashtable & moves, int prime);
void printFile(Hashtable & table);
int main()
{
cout << "Welcome to 2-D Nim (h for help)" << endl;
Matrix game;
Nimber value;
int prime = 11;
Hashtable table = prime;
Hashtable moves = prime;
// Initialize hash table w/ 0 game
for ( ; ; ) {
cout << "prompt> ";
char command;
cin >> command;
switch (command) {
case 'h':
cout << "h\t\tShow options" << endl;
cout << "n\t\tEnter a new game" << endl;
cout << "p\t\tPrint normalized form of current game" << endl;
cout << "v\t\tPrint the value of the current game" << endl;
cout << "a\t\tPrint solved games and values" << endl;
cout << "w\t\tWrite solved games and valuse to file" << endl;
cout << "m\t\tPrint winning moves" << endl;
cout << "q\t\tquit" << endl;
break;
case 'q':
return 0;
case 'n':
value = newGame(game, table, moves, prime);
break;
case 'p':
game.print();
break;
case 'v':
cout << value << endl;
break;
case 'a':
table.print();
break;
case 'w':
printFile(table);
break;
case 'm':
cout << "Best move(s):" << endl;
moves.print();
break;
}
}
}
void printFile(Hashtable & table)
{
cout << "Enter file name: ";
string file;
cin >> file;
table.printToFile(file);
}