-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
177 lines (153 loc) · 4.08 KB
/
main.cpp
File metadata and controls
177 lines (153 loc) · 4.08 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* DO NOT CHANGE THIS FILE (except as noted). */
/* YOUR SUBMISSION MUST WORK CORRECTLY WITH _OUR_ COPY OF THIS FILE. */
/* (You may wish to make temporary changes or insert cout statements */
/* while testing your code. When you're finished testing and debugging, */
/* though, make sure your code works with the original version of this file. */
/*
* This file is a program that runs and animates a simulation of
* Sharks and Fish.
*
* It takes up to four parameters. The first two specify
* the width and height of the ocean. The third parameter specifies the value
* of starveTime. For example, if you run with the following parameters
*
* 25 25 1
*
* then it will animate a 25x25 ocean with a starveTime of 1. If you run
* the file with no parameters, by default it will animate a 50x25
* ocean with a starveTime of 3. With some choices of parameters, the ocean
* quickly dies out; with others, it teems forever.
*
* @author Jonathan Shewchuk with some editing by Mahmoud Fouad
*/
#include <iostream>
#include "Ocean.h"
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include"RunLengthEncoding.h"
using namespace std;
/*
* Default parameters. (You may change these if you wish.)
*/
int i = 5; // Default ocean width
int j = 5; // Default ocean height
int starveTime = 2; // Default shark starvation time
/*
* paint() prints an Ocean.
*/
void paint(Ocean* sea)
{
int width = sea->width();
int height = sea->height();
/* Draw the ocean. */
for (int x = 0; x < width + 2; x++)
{
cout << "-";
}
cout << endl;
for (int y = 0; y < height; y++)
{
cout << "|";
for (int x = 0; x < width; x++)
{
int contents = sea->cellContents(x, y);
if (contents == Ocean::SHARK)
{
cout << 'S';
}
else if (contents == Ocean::FISH)
{
cout << '~';
}
else
{
cout << ' ';
}
}
cout << "|\n";
}
for (int x = 0; x < width + 2; x++)
{
cout << "-";
}
cout << endl;
}
/*
* main() reads the parameters and performs the simulation and animation.
*/
int main(int argc, char **argv)
{
/*
* Read the input parameters.
*/
if (argc > 1)
{
i = atoi(argv[1]);
}
if (argc > 2)
{
j = atoi(argv[2]);
}
if (argc > 3)
{
starveTime = atoi(argv[3]);
}
/*
* Create the initial ocean.
// */
//
// Ocean sea(4, 4,5);
// sea.addShark(2,1);
// sea.addFish(1,0);
//// sea.addFish(0,3);
//// sea.addShark(2,1);
// sea=*sea.miniMax();
//
//
//int type[]={0};
//int length[]={9};
//RunLengthEncoding* sea2=new RunLengthEncoding (3,3,5,type,1,length,1);
//sea2->addFish(0,0);
//
//sea2->addFish(0,1);
//
//int resullt,sizer;
//sea2->nextRun(&resullt,&sizer);
//cout<<resullt<<"\n"<<sizer<<"\n";
//sea2->nextRun(&resullt,&sizer);
//cout<<resullt<<"\n"<<sizer<<"\n";
////
////
////
// Ocean *sea=(sea2->toOcean());
Ocean *sea=new Ocean(4,4,1);
sea->addFish(3,0);
sea->addFish(1,1);
sea->addFish(3,3);
sea->addShark(0,1);
sea->addShark(2,1);
//sea->addShark(4,2);
sea=sea->miniMax();
/*
* Generate the map and add sharks and fish to it
* Visit each cell (in a roundabout order); RANDOMLY (with a specific seed) place a fish, shark,
* or nothing in each.
* Briefly, put your seed as a constant integer (say 0) to create the same map in each run
* If you change the seed, the generated map will differ.
*/
// You generation goes here
/*
* Perform timesteps forever.
*/
//
while (true) // Loop forever
{
system("cls");
paint(sea);
// For fun, you might wish to change the delay in the next line.
Sleep(10000); // Wait one second
sea = (sea->timeStep()); // Simulate a timestep
}
return 0;
}