Last active
August 6, 2019 15:16
-
-
Save Geograph-us/32bbdab9a5b1bc4af16f4a42759ac9ba to your computer and use it in GitHub Desktop.
nc sly.kz 8181
This file contains hidden or 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
const int serverPort = 8181; | |
const string serverAddress = "sly.kz"; | |
void Main() | |
{ | |
using (var client = new TcpClient(serverAddress, serverPort)) | |
using (var networkStream = client.GetStream()) | |
using (var sr = new StreamReader(networkStream)) | |
{ | |
var maxWins = 50; | |
var wins = 0; | |
var send = ""; | |
var received = sr.ReadLine(); | |
Console.WriteLine(received); | |
if (received.StartsWith("Make move:")) | |
{ | |
while (wins < maxWins) | |
{ | |
var pos = 0; | |
while (true) | |
{ | |
received = sr.ReadLine(); | |
Console.WriteLine(received); | |
if (received.StartsWith("You won!")) | |
{ | |
wins++; | |
if (wins >= maxWins) | |
{ | |
received = sr.ReadLine(); | |
Console.WriteLine(received); | |
return; | |
} | |
break; | |
} | |
else if (received.StartsWith("Bad input!")) | |
{ | |
wins = 0; | |
break; | |
} | |
for (int i = 0; i < 8; i++) | |
{ | |
received = sr.ReadLine(); | |
Console.WriteLine(received); | |
if ((pos = received.IndexOf("@")) > -1) | |
{ | |
pos = ((pos - 1) / 4); | |
if (pos % 2 == 0) send = "R"; | |
else send = "L"; | |
send += "\r\n"; | |
networkStream.Write(Encoding.ASCII.GetBytes(send), 0, send.Length); | |
} | |
received = sr.ReadLine(); | |
Console.WriteLine(received); | |
} | |
} | |
} | |
} | |
} | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment