// Generate state from given engine string // Generally always used to parse public UTTTState(String fieldString, String macroString, ZobristHasher zobristHasher, bool weArePlayerOne) { String[] fieldArray = fieldString.Split(','); for (int i = 0; i != 81; i++) { field[i % 9, i / 9] = Int32.Parse(fieldArray[i]); } String[] macroArray = macroString.Split(','); for (int i = 0; i != 9; i++) { macro[i % 3, i / 3] = Int32.Parse(macroArray[i]); } for (int i = 0; i != 81; i++) { moveArray[i % 9, i / 9] = new UTTTMove(i % 9, i / 9); } //Our turn playerNum = (weArePlayerOne ? 1 : 2); this.zobristHasher = zobristHasher; this.hashCode = zobristHasher.getOriginalHashcode(); }
private static void RealMainEatCheese() { TimedSearcher searcher = new TimedSearcher(); ZobristHasher zobristHasher = new ZobristHasher(9, 9, 2); UTTTState currentState = null; int timePerMove; int timebank; String field = null; String macroboard = null; bool weArePlayerOne = false; while (true) { Thread.Sleep(10); String line = Console.In.ReadLine(); if (line.Length == 0) { continue; } Console.Error.WriteLine(line); String[] parts = line.Split(' '); switch (parts[0]) { case "settings": switch (parts[1]) { case "time_per_move": timePerMove = int.Parse(parts[2]); break; case "timebank": timebank = int.Parse(parts[2]); break; case "field": field = parts[2]; break; case "macroboard": macroboard = parts[2]; break; case "your_botid": weArePlayerOne = (int.Parse(parts[2]) == 1); break; } break; case "update": switch (parts[2]) { case "field": field = parts[3]; break; case "macroboard": macroboard = parts[3]; break; } break; case "action": currentState = new UTTTState(field, macroboard, zobristHasher, weArePlayerOne); UTTTMove chosen = searcher.FindBestMove(currentState, 2000); Console.WriteLine($"place_move {chosen.x} {chosen.y}"); Console.Out.Flush(); break; default: // error break; } } }