This repository has been archived by the owner on Jun 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,116 additions
and
1,314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
filter=-legal/copyright,-whitespace/indent,-build/header_guard,-build/include_order,-whitespace/comments | ||
filter=-legal/copyright,-build/header_guard,-whitespace/indent,-whitespace/comments,-build/include_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,76 @@ | ||
#include "Game.h" | ||
#include "CellMap.h" | ||
#include <gameoflife/CellMap.h> | ||
#include <gameoflife/Game.h> | ||
|
||
#include <QFile> | ||
|
||
Game::Game(std:: size_t width, std::size_t height) : generation(0) { | ||
Game::Game(std::size_t width, std::size_t height) : generation(0) { | ||
map = new CellMap(this, width, height); | ||
} | ||
|
||
Game::~Game() { } | ||
Game::~Game() {} | ||
|
||
std::size_t Game::getGeneration() { | ||
return generation; | ||
} | ||
std::size_t Game::getGeneration() { return generation; } | ||
|
||
CellMap* Game::getMap() { | ||
return map; | ||
} | ||
CellMap *Game::getMap() { return map; } | ||
|
||
void Game::nextGeneration() { | ||
++generation; | ||
map->nextGeneration(); | ||
} | ||
|
||
//TODO: Expand world size if necessary | ||
void Game::loadRLE(QString filename){ | ||
|
||
void Game::loadRLE(QString filename) { | ||
map->clear(); | ||
generation = 0; | ||
|
||
QFile file(filename); | ||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) | ||
return; | ||
int width = 0; | ||
int height = 0; | ||
QByteArray data(""); | ||
while(!file.atEnd()) | ||
{ | ||
QByteArray line = file.readLine(); | ||
if(line[0] == '#'){ | ||
continue; | ||
} | ||
if(line[0] == 'x'){ | ||
QList<QByteArray> list = line.split(','); | ||
width = ((list[0].split('='))[1].simplified()).toInt(); | ||
height = ((list[1].split('='))[1].simplified()).toInt(); | ||
continue; | ||
} | ||
data.append(line); | ||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) | ||
return; | ||
int width = 0; | ||
int height = 0; | ||
QByteArray data(""); | ||
while (!file.atEnd()) { | ||
QByteArray line = file.readLine(); | ||
if (line[0] == '#') { | ||
continue; | ||
} | ||
if (line[0] == 'x') { | ||
QList<QByteArray> list = line.split(','); | ||
width = ((list[0].split('='))[1].simplified()).toInt(); | ||
height = ((list[1].split('='))[1].simplified()).toInt(); | ||
continue; | ||
} | ||
data = data.simplified(); | ||
int init_x = map->getWidth()/2 - (int) (width/2); | ||
int init_y = map->getHeight()/2 - (int) (height/2); | ||
data.append(line); | ||
} | ||
data = data.simplified(); | ||
int init_x = map->getWidth() / 2 - static_cast<int>(width / 2); | ||
int init_y = map->getHeight() / 2 - static_cast<int>(height / 2); | ||
|
||
int curr_x = init_x; | ||
int curr_y = init_y; | ||
int curr_x = init_x; | ||
int curr_y = init_y; | ||
|
||
QByteArray qs(""); | ||
for(int i = 0; i < data.length(); ++i) | ||
{ | ||
if(data[i] == '\0') | ||
continue; | ||
int q; | ||
if(data[i] == '$'){ | ||
q = qs.isEmpty() ? 1 : qs.toInt(); | ||
curr_y += q; | ||
curr_x = init_x; | ||
qs.clear(); | ||
} | ||
if(data[i] >= '0' && data[i] <= '9'){ | ||
qs.append(data[i]); | ||
} | ||
if(data[i] == 'o' || data[i] == 'b'){ | ||
q = qs.isEmpty() ? 1 : qs.toInt(); | ||
for (int n = 0; n < q; n++) { | ||
map->changeCellState(curr_x,curr_y,(data[i] == 'o')); | ||
curr_x++; | ||
} | ||
qs.clear(); | ||
QByteArray qs(""); | ||
for (int i = 0; i < data.length(); ++i) { | ||
if (data[i] == '\0') | ||
continue; | ||
int q; | ||
if (data[i] == '$') { | ||
q = qs.isEmpty() ? 1 : qs.toInt(); | ||
curr_y += q; | ||
curr_x = init_x; | ||
qs.clear(); | ||
} | ||
if (data[i] >= '0' && data[i] <= '9') { | ||
qs.append(data[i]); | ||
} | ||
if (data[i] == 'o' || data[i] == 'b') { | ||
q = qs.isEmpty() ? 1 : qs.toInt(); | ||
for (int n = 0; n < q; n++) { | ||
map->changeCellState(curr_x, curr_y, (data[i] == 'o')); | ||
curr_x++; | ||
} | ||
if(data[i] == '!') | ||
break; | ||
qs.clear(); | ||
} | ||
|
||
if (data[i] == '!') | ||
break; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef BIG_INT_HPP | ||
#define BIG_INT_HPP | ||
|
||
#include <gmpxx.h> | ||
#include <string> | ||
|
||
typedef mpz_class BigInt; | ||
|
||
static std::string bigint_to_str(BigInt i) { | ||
std::string str_i = i.get_str(); | ||
std::string result; | ||
if (str_i.size() <= 20) { | ||
return str_i; | ||
} else { | ||
result += str_i[0]; | ||
result += '.'; | ||
result += str_i[1]; | ||
result += str_i[2]; | ||
result += 'e'; | ||
result += std::to_string(str_i.size() - 1); | ||
} | ||
return result; | ||
} | ||
|
||
#endif // BIG_INT_HPP |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.