main.cpp 2.02 KB
Newer Older
Sam Moore's avatar
Sam Moore committed
1
2
3
4
5
6
7
8
9
/**
 * "forfax", a sample Stratego AI for the UCC Programming Competition 2012
 * The main function for the "forfax" AI program
 * @author Sam Moore (matches) [SZM]
 * @website http://matches.ucc.asn.au/stratego
 * @email [email protected] or [email protected]
 * @git git.ucc.asn.au/progcomp2012.git
 */

Sam Moore's avatar
Sam Moore committed
10
11
12
13
14
15
16
17
#include <cstdlib>
#include <iostream>

#include "forfax.h"

using namespace std;

#include <stdio.h>
Sam Moore's avatar
Sam Moore committed
18
19
20
21

/**
 * The AI
 */
Sam Moore's avatar
Sam Moore committed
22
Forfax forfax;
Sam Moore's avatar
Sam Moore committed
23
24
25
26
27
28
29
30

/**
 * The main function
 * @param argc the number of arguments
 * @param argv the arguments
 * @returns exit code 0 for success, something else for error
 * Do I really need to tell you this?
 */
Sam Moore's avatar
Sam Moore committed
31
32
33
34
35
int main(int argc, char ** argv)
{
	setbuf(stdin, NULL);
	setbuf(stdout, NULL);

36

Sam Moore's avatar
Sam Moore committed
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
	Forfax::Status move = forfax.Setup();

	
	while (move == Forfax::OK)
	{
		move = forfax.MakeMove();
	}

	switch (move)
	{
		case Forfax::OK:
			cerr << argv[0] << " Error - Should never see this!\n";
			break;
		case Forfax::NO_NEWLINE:
			cerr << argv[0] << " Error - Expected a new line!\n";
			break;
		case Forfax::EXPECTED_ATTACKER:
			cerr << argv[0] << " Error - Attacking piece does not exist on board!\n";
			break;
		case Forfax::UNEXPECTED_DEFENDER:
			cerr << argv[0] << " Error - Unexpected defending piece on board!\n";
			break;
		case Forfax::NO_ATTACKER:
			cerr << argv[0] << " Error - Couldn't find attacker in list of pieces!\n";
			break;
		case Forfax::NO_DEFENDER:
			cerr << argv[0] << " Error - Couldn't find defender in list of pieces!\n";
			break;
Sam Moore's avatar
Sam Moore committed
65

Sam Moore's avatar
Sam Moore committed
66
67
68
69
70
71
72
73
74
75
76
77
78
		case Forfax::COLOUR_MISMATCH:
			cerr << argv[0] << " Error - Colour of attacker and defender are the same!\n";
			break;
		case Forfax::INVALID_QUERY:
			cerr << argv[0] << " Error - Query did not make sense\n";
			break;
		case Forfax::VICTORY:
			cerr << argv[0] << " Game end - VICTORY!\n";
			break;		
		case Forfax::BOARD_ERROR:
			cerr << argv[0] << " Error - An error occurred with the board!\n";
			break;
	}
Sam Moore's avatar
Sam Moore committed
79

Sam Moore's avatar
Sam Moore committed
80
81
82
83
84
	cerr << "Final board state:\n";
	forfax.PrintBoard(cerr);

	cerr << "Forfax is now exiting!\n";
	
Sam Moore's avatar
Sam Moore committed
85
86
87
88
89
90
	
	exit(EXIT_SUCCESS);
	return 0;

	
}
91

Sam Moore's avatar
Sam Moore committed
92