-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
136 lines (121 loc) · 5.19 KB
/
Program.cs
File metadata and controls
136 lines (121 loc) · 5.19 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
using System;
using System.Collections.Generic;
namespace Life_Console
{
public class Program
{
static CLI cli = new CLI();
static void Main(string[] args)
{
string action = "";
while (action != "quit")
{
action = cli.RunMainMenu();
switch (action)
{
case "custom":
Setup();
break;
case "tumble":
TumblerTest();
break;
}
}
}
/// <summary>
/// Setup your own board!
/// </summary>
static void Setup()
{
int width = cli.IntegerGetter("\nSpecify the board dimensions!\nWidth?");
int height = cli.IntegerGetter("\nAnd height?");
bool randomizedPopulation = cli.BoolGetter("\nRandomized population?");
int offset = randomizedPopulation ?
cli.IntegerGetter(
"\nOffset? - To create an initial border of dead space", // Question to display
0, // minimum value
(width < height ? width : height) / 2 // Maximum value
)
: 0;
int population = randomizedPopulation ? cli.IntegerGetter("\nPopulation Percentage? 0-100", 0, 100) : 0;
bool clownVomit = cli.BoolGetter("\nEnable Clown Vomit?\nIt's.. uh.. Special..");
Board board = new Board(height, width, clownVomit, offset, population);
if(!randomizedPopulation) EditBoard(board);
cli.WriteLine("\n---------------------- B O A R D ------------------------\n");
cli.DisplayBoard(board);
GameLoop(board, cli.IntegerGetter("How many rounds do you want the game to progress per calculation? (Skipped rounds will still be displayed)", 1, 500));
}
/// <summary>
/// Opens a special menu, where you can flip the individual cells of the board.
/// </summary>
/// <param name="board"></param>
static void EditBoard(Board board)
{
string action = "";
Coordinate coordinate = new Coordinate(-1, -1);
while (action != "done")
{
action = cli.RunEditBoardMenu(board);
if(int.TryParse(action, out int potentialX) && potentialX > 0 && potentialX <= board.RowCount)
{
coordinate.X = potentialX - 1;
coordinate.Y = cli.IntegerGetter("Column = " + potentialX + ", Row = ..?", 1, board.ColumnCount) - 1;
board.State[coordinate.Y][coordinate.X] = !board.State[coordinate.Y][coordinate.X];
}
}
}
/// <summary>
/// Runs a tumbler. Tests the Stagnation Detector, GameLoop() and AdvanceLifeCycle()
/// </summary>
static void TumblerTest()
{
Console.WriteLine("\n\n################# Tumbler test mode, engaged! #####################\n\nThe TUmbler is an infinitely repeating arrangement, used for testing the Stagnation Detection™ system.\n");
// 7x9
Board testBoard = new Board(
new bool[7][]
{
new bool[]{ false, true, false, false, false, false, false, true, false },
new bool[]{ true, false, true, false, false, false, true, false, true },
new bool[]{ true, false, false, true, false, true, false, false, true },
new bool[]{ false, false, true, false, false, false, true, false, false },
new bool[]{ false, false, true, true, false, true, true, false, false },
new bool[]{ false, false, false, false, false, false, false, false, false },
new bool[]{ false, false, false, false, false, false, false, false, false }
});
GameLoop(testBoard, 1);
}
/// <summary>
/// The game loop. Runs until stagnation is detected or you type "Exit"
/// </summary>
/// <param name="board"></param>
/// <param name="progression"></param>
static void GameLoop(Board board, int progression)
{
int round = 0;
string action = "";
// Game loop
while (action != "exit" && !board.Stagnated)
{
for (int i = 0; i < progression; i++)
{
round++;
AdvanceLifeCycle(board);
if (board.Stagnated) i = progression;
cli.DisplayRoundResult(round, board);
}
cli.DisplayPostProgressionOptions(board.Stagnated);
action = cli.ReadLineLowered();
}
}
/// <summary>
/// Advances the board one life-cycle
/// </summary>
/// <param name="board"></param>
static void AdvanceLifeCycle(Board board)
{
List<Coordinate> flipList = board.FindFlips();
board.ApplyFlips(flipList);
board.Hash();
}
}
}