public void tileArr2TileStr() { string expected = "123456789m57h"; int[] tileArr; TileOperation.TileStr2TileArray(expected, out tileArr); Assert.AreEqual <string>(expected, TileOperation.TileArr2String(tileArr)); }
public void scanChitoitsu_test() { string testStr = ""; int[] tileArray = null; int excepted = 0; testStr = "1155m7788p1122s55h"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); testStr = "1155m7788p1122s57h"; excepted = 0; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); testStr = "11155m7788p1122s7h"; excepted = 0; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); testStr = "111555m7788p1122s"; excepted = 1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); testStr = "111155m7788p1122s"; excepted = 1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); testStr = "12356p333s11m5556h"; excepted = 3; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); testStr = "19m"; excepted = 100; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanChitoitsu(tileArray), testStr + " test failed"); }
static void AddNextScanLine(TileCheck checkOp, TileOperation fillOp, int min, int max, int range_min, int range_max, int y, bool isNext, Direction4 dir, Stack <Tuple <int, int, int, Direction4, bool, bool> > stack) { int rMinX = range_min; bool inRange = false; int x = range_min; for (; x <= range_max; x++) { //// skip testing, if testing previous line within previous range bool empty = (isNext || (x <min || x> max)) && checkOp(x, y); if (!inRange && empty) { rMinX = x; inRange = true; } else if (inRange && !empty) { stack.Push(new Tuple <int, int, int, Direction4, bool, bool>(rMinX, x - 1, y, dir, rMinX == range_min, false)); inRange = false; } if (inRange) { fillOp(x, y); } if (!isNext && x == min) { break; } } if (inRange) { stack.Push(new Tuple <int, int, int, Direction4, bool, bool>(rMinX, x - 1, y, dir, rMinX == range_min, true)); } }
public void scanKokushi_test() { string testStr = ""; int[] tileArray = null; int excepted = 0; testStr = "19m19p19s12234567h"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanKokushi(tileArray), testStr + " test failed"); testStr = "19m19p129s1234567h"; excepted = 0; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanKokushi(tileArray), testStr + " test failed"); testStr = "789m49p19s1234567h"; excepted = 2; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanKokushi(tileArray), testStr + " test failed"); testStr = "123456789m1h2579s"; excepted = 9; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanKokushi(tileArray), testStr + " test failed"); testStr = "123456789m25788s"; excepted = 11; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanKokushi(tileArray), testStr + " test failed"); testStr = "19m"; excepted = 100; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.ScanKokushi(tileArray), testStr + " test failed"); }
public void calculateShanten_test() { string testStr = ""; int[] tileArray = null; int excepted = 0; testStr = "123m456p789s11122h"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "11112233m"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "1144p5577m4466s33h"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "19m19p19s12334567h"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "22233m123s456789p"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "11123456788999p"; excepted = -1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "11122245679999s"; excepted = 0; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "233789m456s111p11h"; excepted = 0; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "111345677m15s456s"; excepted = 1; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "11345677m159s456p"; excepted = 2; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "1589m1358s13588p4h"; excepted = 5; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); testStr = "1589m1358s258p457h"; excepted = 6; TileOperation.TileStr2TileArray(testStr, out tileArray); Assert.AreEqual(excepted, TileOperation.CalculateShanten(tileArray), testStr + " test failed"); }
public void tileStr2TileArray_test() { string testStr = ""; int[] excepted = new int[34], actual = null; testStr = "11234m"; excepted = new int[34]; excepted[0] = 2; excepted[1] = 1; excepted[2] = 1; excepted[3] = 1; TileOperation.TileStr2TileArray(testStr, out actual); CollectionAssert.AreEqual(excepted, actual, testStr + " test failed"); testStr = "56p"; excepted = new int[34]; excepted[13] = 1; excepted[14] = 1; TileOperation.TileStr2TileArray(testStr, out actual); CollectionAssert.AreEqual(excepted, actual, testStr + " test failed"); testStr = "11112233m"; excepted = new int[34]; excepted[0] = 4; excepted[1] = 2; excepted[2] = 2; TileOperation.TileStr2TileArray(testStr, out actual); CollectionAssert.AreEqual(excepted, actual, testStr + " test failed"); testStr = "11234m56p789s1117h"; excepted = new int[34]; excepted[0] = 2; excepted[1] = 1; excepted[2] = 1; excepted[3] = 1; excepted[13] = 1; excepted[14] = 1; excepted[24] = 1; excepted[25] = 1; excepted[26] = 1; excepted[27] = 3; excepted[33] = 1; TileOperation.TileStr2TileArray(testStr, out actual); CollectionAssert.AreEqual(excepted, actual, testStr + " test failed"); testStr = "1235h"; excepted = new int[34]; excepted[27] = 1; excepted[28] = 1; excepted[29] = 1; excepted[31] = 1; TileOperation.TileStr2TileArray(testStr, out actual); CollectionAssert.AreEqual(excepted, actual, testStr + " test failed"); testStr = "7h"; excepted = new int[34]; excepted[33] = 1; TileOperation.TileStr2TileArray(testStr, out actual); CollectionAssert.AreEqual(excepted, actual, testStr + " test failed"); testStr = "^&$&*^"; try { TileOperation.TileStr2TileArray(testStr, out actual); } catch (Exception e) { StringAssert.Contains(e.Message, MahjongErrorCode.TilesStrError.ToString()); } testStr = "123456789"; try { TileOperation.TileStr2TileArray(testStr, out actual); } catch (Exception e) { StringAssert.Contains(e.Message, MahjongErrorCode.TilesStrError.ToString()); } testStr = "s"; try { TileOperation.TileStr2TileArray(testStr, out actual); } catch (Exception e) { StringAssert.Contains(e.Message, MahjongErrorCode.TilesStrError.ToString()); } }
public void ProcessEvents() { TilePainter me = (TilePainter)target; int controlID = GUIUtility.GetControlID(1778, FocusType.Passive); EditorWindow currentWindow = EditorWindow.mouseOverWindow; if (currentWindow && AmHovering(Event.current)) { Event current = Event.current; bool leftbutton = (current.button == 0); switch (current.type) { case EventType.KeyDown: if (current.keyCode == KeyCode.S) { operation = TileOperation.Sampling; } if (current.keyCode == KeyCode.X) { operation = TileOperation.Erasing; } current.Use(); return; case EventType.KeyUp: operation = TileOperation.None; if (current.keyCode == KeyCode.Space) { me.Turn(); } if (current.keyCode == KeyCode.B) { me.CycleColor(); } current.Use(); return; case EventType.MouseDown: if (leftbutton) { if (operation == TileOperation.None) { operation = TileOperation.Drawing; } me.Drag(current.mousePosition, operation); current.Use(); return; } break; case EventType.MouseDrag: if (leftbutton) { if (operation != TileOperation.None) { me.Drag(current.mousePosition, operation); current.Use(); } return; } break; case EventType.MouseUp: if (leftbutton) { operation = TileOperation.None; current.Use(); return; } break; case EventType.MouseMove: me.Resize(); current.Use(); break; case EventType.Repaint: break; case EventType.Layout: HandleUtility.AddDefaultControl(controlID); break; } } }
public static void FillArray(int arrayWidth, int arrayHeight, TileCheck checkOp, TileOperation fillOp, Loc2D loc) { Stack <Tuple <int, int, int, Direction4, bool, bool> > stack = new Stack <Tuple <int, int, int, Direction4, bool, bool> >(); stack.Push(new Tuple <int, int, int, Direction4, bool, bool>(loc.X, loc.X, loc.Y, Direction4.None, true, true)); fillOp(loc.X, loc.Y); while (stack.Count > 0) { Tuple <int, int, int, Direction4, bool, bool> this_should_really_be_a_class = stack.Pop(); Direction4 dir = this_should_really_be_a_class.Item4; int minX = this_should_really_be_a_class.Item1; int maxX = this_should_really_be_a_class.Item2; int y = this_should_really_be_a_class.Item3; bool goLeft = this_should_really_be_a_class.Item5; bool goRight = this_should_really_be_a_class.Item6; int newMinX = minX; if (goLeft) { while (newMinX - 1 >= 0 && checkOp(newMinX - 1, y)) { newMinX--; fillOp(newMinX, y); } } int newMaxX = maxX; if (goRight) { while (newMaxX + 1 < arrayWidth && checkOp(newMaxX + 1, y)) { newMaxX++; fillOp(newMaxX, y); } } minX--; maxX++; if (y < arrayHeight - 1) { AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y + 1, dir != Direction4.Up, Direction4.Down, stack); } if (y > 0) { AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y - 1, dir != Direction4.Down, Direction4.Up, stack); } } }
public static void FillArray(int arrayWidth, int arrayHeight, TileCheck checkOp, TileOperation fillOp, Loc2D loc) { var stack = new Stack <StackItem>(); stack.Push(new StackItem(loc.X, loc.X, loc.Y, Direction4.None, true, true)); fillOp(loc.X, loc.Y); while (stack.Count > 0) { var item = stack.Pop(); int minX = item.MinX; int maxX = item.MaxX; int y = item.Y; Direction4 dir = item.Direction; bool goLeft = item.GoLeft; bool goRight = item.GoRight; int newMinX = minX; if (goLeft) { while (newMinX - 1 >= 0 && checkOp(newMinX - 1, y)) { newMinX--; fillOp(newMinX, y); } } int newMaxX = maxX; if (goRight) { while (newMaxX + 1 < arrayWidth && checkOp(newMaxX + 1, y)) { newMaxX++; fillOp(newMaxX, y); } } minX--; maxX++; if (y < arrayHeight - 1) { AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y + 1, dir != Direction4.Up, Direction4.Down, stack); } if (y > 0) { AddNextScanLine(checkOp, fillOp, minX, maxX, newMinX, newMaxX, y - 1, dir != Direction4.Down, Direction4.Up, stack); } } }