-
-
Save Yonom/83226bd5e94e6319a090 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using PlayerIOClient; | |
// The Upload test! | |
// This class checks the capabilities of a block error checking algorithm. | |
// | |
// Usage: | |
// var test = new UploadTest(con); | |
// test.Test(); | |
// // TODO: wait for block placement to finish | |
// test.Check(); | |
// | |
// The test is passed if: | |
// - the 100x60 area is filled with basic blue blocks. | |
// - this above conditions ALWAYS remains true regardless of lag and latency. | |
// To test this behavior, you can reduce the delay between blocks. | |
// | |
// Scores may go up to 4000. Valid solutions must have a minimum score of 1! | |
// You may compare valid sulutions by the average time they take to complete. | |
class UploadTest : UploadTestBase | |
{ | |
public UploadTest(Connection connection) | |
: base(connection) | |
{ | |
// Do nessessary initialization here (ex. pass upload class) | |
} | |
protected override void Upload(int layer, int x, int y, int block) | |
{ | |
// Code to upload blocks | |
// e.g. connection.Send(token, layer, x, y, block); | |
} | |
} | |
////////////////////// DO NOT EDIT ANYTHING BELOW THIS LINE //////////////////////// | |
abstract class UploadTestBase | |
{ | |
protected UploadTestBase(Connection connection) | |
{ | |
connection.OnMessage += this.connection_OnMessage; | |
} | |
protected abstract void Upload(int layer, int x, int y, int block); | |
public void Test() | |
{ | |
this._sw = Stopwatch.StartNew(); | |
for (var x = 0; x < 20; x++) | |
for (var y = 0; y < 100; y++) | |
{ | |
this.Upload(0, x, y, 10); | |
} | |
for (var x = 20; x < 40; x++) | |
for (var y = 0; y < 100; y++) | |
{ | |
this.Upload(0, x, y, 12); | |
this.Upload(0, x, y, 10); | |
} | |
for (var x = 40; x < 60; x++) | |
for (var y = 0; y < 100; y++) | |
{ | |
this.Upload(0, x, y, 10); | |
this.Upload(0, x, y, 12); | |
this.Upload(0, x, y, 10); | |
} | |
} | |
public void Check() | |
{ | |
var count = this._blocks.Cast<int>().Count(i => i == 10); | |
if (count == this._blocks.Length) | |
Console.WriteLine("Passed! Score: " + this._redCount); | |
else | |
Console.WriteLine("Failed, not every block is blue."); | |
Console.WriteLine("Took " + this._sw.ElapsedMilliseconds + "ms."); | |
} | |
private readonly int[,] _blocks = new int[60, 100]; | |
private int _redCount; | |
private Stopwatch _sw; | |
void connection_OnMessage(object sender, Message e) | |
{ | |
if (e.Type != "b") return; | |
var x = e.GetInt(1); | |
var y = e.GetInt(2); | |
if (x >= 60 || y >= 100) return; | |
var b = e.GetInt(3); | |
if (b == 12) this._redCount++; | |
this._blocks[x, y] = b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment