TicTacToe

Run Settings
LanguageC#
Language Version
Run Command
using System; using System.Collections.Generic; using System.Linq; class MainClass { static void Main() { var board = new Board(); PlayState move; move = TicTacToe.Next(board, Player.X, 0, 0); Console.WriteLine(move); move = TicTacToe.Next(board, Player.O, 1, 1); Console.WriteLine(move); move = TicTacToe.Next(board, Player.X, 1, 0); Console.WriteLine(move); move = TicTacToe.Next(board, Player.O, 2, 1); Console.WriteLine(move); move = TicTacToe.Next(board, Player.X, 2, 0); Console.WriteLine(move); } } public enum Player { NoPlayerSet, X, O, } public class Board { public Player[,] Grid = new Player[3, 3]; public Player CurrentPlayer = Player.X; } public enum PlayState { Illegal, Continue, Draw, X_Winner, O_Winner, } public static class TicTacToe { public static PlayState Next(Board board, Player player, int x, int y) { if (board.CurrentPlayer != player) { return PlayState.Illegal; } if (board.Grid[x, y] != Player.NoPlayerSet) { return PlayState.Illegal; } board.Grid[x, y] = board.CurrentPlayer; board.CurrentPlayer = board.CurrentPlayer == Player.X ? Player.O : Player.X; return PlayState.Continue; } }
Editor Settings
Theme
Key bindings
Full width
Lines