Skip to content

Commit

Permalink
seeding for 2 more referees, bugfix for BTTC
Browse files Browse the repository at this point in the history
  • Loading branch information
eulerscheZahl committed Aug 20, 2017
1 parent 3449429 commit 452585b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 31 deletions.
43 changes: 28 additions & 15 deletions BackToTheCode/BackToTheCodeReferee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,28 @@ class BackToTheCodeReferee
{
public static void Main(string[] args)
{
string path = args.Length == 1 ? args[0] : null;
string line = Console.ReadLine();
int playerCount = int.Parse(line.Split()[1]);
Board board = new Board(playerCount);
int tick = 0;
while (board.Tick ()) {
tick++;
if (path != null)
{
Bitmap bmp = board.Draw();
bmp.Save(path + System.IO.Path.DirectorySeparatorChar + $"{tick:000}.png");
bmp.Dispose();
string path = args.Length == 1 ? args [0] : null;

int seed = -1;
while (true) {
string[] lineParts = Console.ReadLine ().Split ();
if (lineParts [0] == "###Seed")
seed = int.Parse (lineParts [1]);
else if (lineParts [0] == "###Start") {
int playerCount = int.Parse (lineParts [1]);
Board board = new Board (playerCount, seed);
int tick = 0;
while (board.Tick ()) {
tick++;
if (path != null) {
Bitmap bmp = board.Draw ();
bmp.Save (path + System.IO.Path.DirectorySeparatorChar +$"{tick:000}.png");
bmp.Dispose ();
}
}
Console.WriteLine (board.Ranking ());
}
}
Console.WriteLine (board.Ranking ());
}
}

Expand All @@ -36,9 +43,9 @@ class Board
List<Field> allFields = new List<Field>();
private int round = 0;

public Board(int playerCount)
public Board(int playerCount, int seed)
{
Random random = new Random();
Random random = seed >= 0 ? new Random (seed) : new Random ();
for (int i = 0; i < playerCount; i++) {
players.Add(new Player(i, random.Next(WIDTH), random.Next(HEIGHT)));
}
Expand All @@ -48,6 +55,12 @@ public Board(int playerCount)
allFields.Add (grid [x, y]);
}
}

foreach (Player p in players) {
if (players.Any(q => p != q && p.X == q.X && p.Y == q.Y))
continue;
grid[p.X, p.Y].Conquer(p.ID, round);
}
}

public Bitmap Draw() {
Expand Down
38 changes: 22 additions & 16 deletions TheGreatEscape/TheGreatEscapeReferee.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
Expand All @@ -7,23 +7,28 @@ class TheGreatEscapeReferee
{
public static void Main(string[] args)
{
string path = args.Length == 1 ? args[0] : null;
string path = args.Length == 1 ? args [0] : null;

int playerCount = int.Parse(Console.ReadLine().Split()[1]);

Board board = new Board(playerCount);
if (path != null)
{
Bitmap bmp = board.Draw();
bmp.Save(path + System.IO.Path.DirectorySeparatorChar + "000.png");
bmp.Dispose();
}
int seed = -1;
while (true) {
string[] lineParts = Console.ReadLine ().Split ();
if (lineParts [0] == "###Seed")
seed = int.Parse (lineParts [1]);
else if (lineParts [0] == "###Start") {
int playerCount = int.Parse (lineParts [1]);
Board board = new Board (playerCount, seed);
if (path != null) {
Bitmap bmp = board.Draw ();
bmp.Save (path + System.IO.Path.DirectorySeparatorChar + "000.png");
bmp.Dispose ();
}

while (board.Play())
{
board.Tick(path);
while (board.Play ()) {
board.Tick (path);
}
board.DeclareWinner ();
}
}
board.DeclareWinner();
}

class Board
Expand All @@ -45,8 +50,9 @@ class Board
private static int[,] offset = new int[,] { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
private static string[] directions = new string[] { "DOWN", "RIGHT", "UP", "LEFT" };

public Board(int playerCount)
public Board(int playerCount, int seed)
{
if (seed >= 0) random = new Random(seed);
this.playerCount = playerCount;
for (int i = 0; i < playerCount; i++)
{
Expand Down

0 comments on commit 452585b

Please sign in to comment.