public Ithaka(string json) { Serialized data = JsonConvert.DeserializeObject <Serialized>(json); this.players = data.players; this.currplayer = data.currplayer; this.board = data.board.ToCharArray(); this.lastmoved = data.lastmoved; this.lastmove = data.lastmove; this.states = data.states; this.grid = new SquareFixed(4, 4); this.winner = data.winner; this.gameover = data.gameover; this.chatmsgs = new List <string>(); }
public Ithaka(string[] players) { if (players.Length != 2) { throw new System.ArgumentException("You must pass an array of exactly two strings representing the players."); } var set = new HashSet <string>(players); if (set.Count != players.Length) { throw new System.ArgumentException("The list of players must contain no duplicates."); } this.players = players; this.currplayer = 0; this.board = "YYRRY--RB--GBBGG".ToCharArray(); this.states = new Dictionary <string, int>(); this.lastmoved = -1; this.lastmove = ""; this.grid = new SquareFixed(4, 4); this.chatmsgs = new List <string>(); }
public void TestGrids() { //Common Assert.Equal(new Tuple <int, int>(0, 0), Common.Label2Coords("a1")); Assert.Equal(new Tuple <int, int>(25, 122), Common.Label2Coords("z123")); Assert.Equal("a1", Common.Coords2Label(0, 0)); Assert.Equal("z123", Common.Coords2Label(25, 122)); Action shortlbl = () => Common.Label2Coords("a"); Assert.Throws <ArgumentException>(shortlbl); Action badlet = () => Common.Label2Coords("11"); Assert.Throws <ArgumentException>(badlet); Action negy = () => Common.Label2Coords("a-20"); Assert.Throws <ArgumentException>(negy); Action badnum = () => Common.Label2Coords("aa"); Assert.Throws <FormatException>(badnum); Action smallx = () => Common.Coords2Label(-1, 0); Assert.Throws <ArgumentException>(smallx); Action bigx = () => Common.Coords2Label(100, 0); Assert.Throws <ArgumentException>(bigx); Action smally = () => Common.Coords2Label(0, -1); Assert.Throws <ArgumentException>(smally); //Face Assert.Equal(new Face(0, 0), new Face(0, 0)); Assert.NotEqual(new Face(0, 0), new Face(0, 1)); Assert.Equal(new Face(0, 0), new Face("a1")); HashSet <Face> nodiags = new HashSet <Face>() { new Face(0, 1), new Face(1, 0), new Face(0, -1), new Face(-1, 0) }; HashSet <Face> withdiags = new HashSet <Face>() { new Face(0, 1), new Face(1, 1), new Face(1, 0), new Face(1, -1), new Face(0, -1), new Face(-1, -1), new Face(-1, 0), new Face(-1, 1) }; Face baseface = new Face(0, 0); Assert.Equal(baseface.Neighbours(false), nodiags); Assert.Equal(baseface.Neighbours(true), withdiags); Assert.Equal(baseface.Neighbour(Dirs.N), new Face(0, 1)); Assert.Equal(baseface.Neighbour(Dirs.NE, 2), new Face(2, 2)); Assert.Equal(baseface.Neighbour(Dirs.E, 2), new Face(2, 0)); Assert.Equal(baseface.Neighbour(Dirs.SE, 1), new Face(1, -1)); Assert.Equal(baseface.Neighbour(Dirs.S), new Face(0, -1)); Assert.Equal(baseface.Neighbour(Dirs.SW, 2), new Face(-2, -2)); Assert.Equal(baseface.Neighbour(Dirs.W, 2), new Face(-2, 0)); Assert.Equal(baseface.Neighbour(Dirs.NW), new Face(-1, 1)); Assert.True(baseface.OrthTo(new Face(0, 1))); Assert.True(baseface.OrthTo(new Face(1, 0))); Assert.False(baseface.OrthTo(new Face(2, 5))); Assert.True(baseface.DiagTo(new Face(1, 1))); Assert.True(baseface.DiagTo(new Face(-4, -4))); Assert.False(baseface.DiagTo(new Face(0, 1))); Assert.False(baseface.DiagTo(new Face(2, 5))); Assert.Null(baseface.DirectionTo(baseface)); Assert.Equal(Dirs.N, baseface.DirectionTo(new Face(0, 10))); Assert.Equal(Dirs.NE, baseface.DirectionTo(new Face(2, 5))); Assert.Equal(Dirs.E, baseface.DirectionTo(new Face(5, 0))); Assert.Equal(Dirs.SE, baseface.DirectionTo(new Face(3, -3))); Assert.Equal(Dirs.S, baseface.DirectionTo(new Face(0, -3))); Assert.Equal(Dirs.SW, baseface.DirectionTo(new Face(-3, -5))); Assert.Equal(Dirs.W, baseface.DirectionTo(new Face(-5, 0))); Assert.Equal(Dirs.NW, baseface.DirectionTo(new Face(-1, 1))); //Action nullobj = () => baseface.Between(null); //Assert.Throws<ArgumentException>(nullobj); Action eqobj = () => baseface.Between(baseface); Assert.Throws <ArgumentException>(eqobj); Action eccentric = () => baseface.Between(new Face(1, 20)); Assert.Throws <ArgumentException>(eccentric); List <Face> comp = new List <Face>() { new Face(1, 1), new Face(2, 2), new Face(3, 3) }; Assert.Equal(comp, baseface.Between(new Face(4, 4))); //Edge //Vertex //SquareFixed SquareFixed basegrid = new SquareFixed(2, 2); Assert.Equal( new HashSet <Face>() { new Face(0, 0), new Face(0, 1), new Face(1, 0), new Face(1, 1) }, basegrid.Faces() ); Assert.Equal( new HashSet <Vertex>() { new Vertex(0, 0), new Vertex(1, 0), new Vertex(2, 0), new Vertex(0, 1), new Vertex(1, 1), new Vertex(2, 1), new Vertex(0, 2), new Vertex(1, 2), new Vertex(2, 2) }, basegrid.Vertices() ); Assert.Equal( new HashSet <Edge>() { new Edge(0, 0, Dirs.W), new Edge(0, 0, Dirs.S), new Edge(0, 1, Dirs.W), new Edge(0, 1, Dirs.S), new Edge(1, 0, Dirs.W), new Edge(1, 0, Dirs.S), new Edge(1, 1, Dirs.W), new Edge(1, 1, Dirs.S), new Edge(0, 2, Dirs.S), new Edge(1, 2, Dirs.S), new Edge(2, 1, Dirs.W), new Edge(2, 0, Dirs.W) }, basegrid.Edges() ); Assert.Equal((double)0, basegrid.Face2FlatIdx(new Face(0, 0))); Assert.Equal((double)1, basegrid.Face2FlatIdx(new Face(1, 0))); Assert.Equal((double)2, basegrid.Face2FlatIdx(new Face(0, 1))); Assert.Equal((double)3, basegrid.Face2FlatIdx(new Face(1, 1))); Action badface = () => basegrid.Face2FlatIdx(new Face(2, 2)); Assert.Throws <ArgumentException>(badface); Assert.Equal(new Face(0, 0), basegrid.FlatIdx2Face(0)); Assert.Equal(new Face(1, 0), basegrid.FlatIdx2Face(1)); Assert.Equal(new Face(0, 1), basegrid.FlatIdx2Face(2)); Assert.Equal(new Face(1, 1), basegrid.FlatIdx2Face(3)); Assert.True(basegrid.ContainsFace(new Face(1, 1))); Assert.False(basegrid.ContainsFace(new Face(10, 10))); }