summaryrefslogtreecommitdiffstats
path: root/labb8/src/types.h
blob: 606f3985b16a854cd3cd807a6c99fee1f820874e (plain) (blame)
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
82
83
84
85
86
/*
 * TDDD86 Trailblazer
 * This file declares fundamental types used by the Trailblazer assignment.
 *
 * Please do not modify this provided file. Your turned-in files should work
 * with an unmodified version of all provided code files.
 *
 * Author: Marty Stepp, Keith Schwarz, et al
 * Slight modifications by Tommy Farnqvist
 */

#ifndef _types_h
#define _types_h

/* Type: Loc
 *
 * A type representing a location in the world, represented as a pair of a row
 * and a column.
 */
struct TBLoc {
    int row;
    int col;
};

/* Utility function to construct a Loc from its location. */
TBLoc makeLoc(int row, int col);

/* Type: Color
 *
 * An enumerated type representing a color for a node during an execution of
 * Dijkstra's algorithm or A* search.
 */
enum Color {
    UNCOLORED, WHITE, GRAY, YELLOW, GREEN, RED
};

/* Type: Edge
 *
 * A type representing an edge in the grid, as encoded by its start and end node.
 * This type will be useful when implementing Kruskal's algorithm, though you may
 * also find it useful when writing Dijkstra's algorithm or A* search.
 */
struct TBEdge {
    TBLoc start;
    TBLoc end;
};

/* Utility function to create an Edge from its endpoints. */
TBEdge makeEdge(TBLoc start, TBLoc end);



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* The functions below this point are provided for convenience and are not
 * strictly necessary for your implementation.
 */

/* Comparison operators for Loc and Edge.    Our Map and Set type cannot store
 * custom structs as keys (for a map) or values (for a set) unless they can be
 * compared with the relational operators.  You will probably not directly use
 * these in your solution, but you're welcome to do so if you find them useful.
 */
bool operator <  (TBLoc lhs, TBLoc rhs);
bool operator >  (TBLoc lhs, TBLoc rhs);
bool operator == (TBLoc lhs, TBLoc rhs);
bool operator != (TBLoc lhs, TBLoc rhs);
bool operator <= (TBLoc lhs, TBLoc rhs);
bool operator >= (TBLoc lhs, TBLoc rhs);

bool operator <  (TBEdge lhs, TBEdge rhs);
bool operator >  (TBEdge lhs, TBEdge rhs);
bool operator == (TBEdge lhs, TBEdge rhs);
bool operator != (TBEdge lhs, TBEdge rhs);
bool operator <= (TBEdge lhs, TBEdge rhs);
bool operator >= (TBEdge lhs, TBEdge rhs);

/* Hash function for Loc and Edge.  These functions are provided so that you can
 * store Locs and Edges in our HashMap or HashSet type, which require a hashCode
 * function to be available.    You will probably not directly use these in your
 * solution, but you're welcome to do so if you find them useful.
 */
int hashCode(TBLoc l);
int hashCode(TBEdge e);

#endif