public void WinEndsTheSearchForPlayerY() { HexBoard board = new HexBoard(5); PlayToWinInOneMove(board, false); Minimax minimax = MakeMinimaxForBoard(board); const int SearchDepth = 4; MinimaxResult bestMove = minimax.DoMinimax(SearchDepth, false); Location win = new Location(0, 3); Assert.AreEqual(win, bestMove.Move, "wrong win location"); // do: test that locations after 0, 4 aren't even looked at. A win ends the search IList <Location> locationsExamined = minimax.DebugDataItems .Where(d => d.Lookahead == SearchDepth) .Select(d => d.Location).ToList(); Assert.IsTrue(locationsExamined.Count > 0, "No locations examined"); Assert.IsTrue(locationsExamined.Contains(win), "Locations examined does not contain win"); Location unexpected = new Location(4, 4); Assert.IsFalse(locationsExamined.Contains(unexpected), "Should not have examined location " + unexpected + " after win"); }
private static void PlayerScoreBlankBoard(IPathLengthFactory pathLengthFactory) { HexBoard hexBoard = new HexBoard(BoardSize); PathLengthBase pathLength = pathLengthFactory.CreatePathLength(hexBoard); // blank board int xScore = pathLength.PlayerScore(true); int yScore = pathLength.PlayerScore(false); Assert.AreEqual(xScore, yScore, "x and y score"); // no advantage int equalMoveScore = pathLength.SituationScore(); Assert.AreEqual(equalMoveScore, 0, "equalMoveScore"); // all cells still on the clean path pathLength.PlayerScore(true); List <Location> cleanPathX = pathLength.GetCleanPath(true); pathLength.PlayerScore(false); List <Location> cleanPathY = pathLength.GetCleanPath(false); const int AllCellsCount = BoardSize * BoardSize; Assert.AreEqual(AllCellsCount, cleanPathX.Count, "Clean path x should have all cells"); Assert.AreEqual(AllCellsCount, cleanPathY.Count, "Clean path y should have all cells"); }
void DefaultInitialization() { int numPlayers = 2; int boardRadius = 2; int hp = 10; List <Ability> abilities = new List <Ability>(); abilities.Add(new Ability(TargetType.Location, EffectType.Path, 0, 3, 3, 2, true, "Move")); abilities.Add(new Ability(TargetType.Unit, EffectType.Harm, 4, 3, 6, 2, false, "Attack")); GameObject hex = GameObject.Find("Base Hex"); board = new GameObject().AddComponent <HexBoard>(); board.AddBigHex(hex, boardRadius, 0, 0, true); hex.SetActive(false); GameObject charObj = GameObject.Find("Base Character"); players = new Player[numPlayers]; for (int i = 0; i < numPlayers; i++) { GameObject playerObj = new GameObject(); Player newPlayer = playerObj.AddComponent <Player>(); newPlayer.Initialize("Player " + i); Character newCharacter = Object.Instantiate(charObj).AddComponent <Character>(); int charq = boardRadius - 2 * i * boardRadius; int charr = 0; newCharacter.Initialize(newPlayer, charq, charr, hp, abilities, "Char " + i); newPlayer.AddCharacter(newCharacter); AddCharacter(newCharacter, charq, charr); } charObj.SetActive(false); }
public bool ReadDevice(DeviceOperation op) { var device = Config.Device; var flashSize = device.Flash.Size; var eepromSize = device.Eeprom.Size; var fusesSize = device.FuseBits.Size; var locksSize = device.LockBits.Size; op.FlashSize += flashSize; op.EepromSize += eepromSize; op.FusesSize += fusesSize; op.LocksSize += locksSize; var flashData = new byte[flashSize]; var eepData = new byte[eepromSize]; var fusesData = new byte[fusesSize]; var locksData = new byte[locksSize]; using (var programmer = CreateProgrammer(op)) { using (programmer.Start()) { programmer.ReadPage(0, AvrMemoryType.Flash, flashData, 0, flashSize); programmer.ReadPage(0, AvrMemoryType.Eeprom, eepData, 0, eepromSize); programmer.ReadPage(device.FuseBits.StartAddress, device.FuseBits.Location ?? AvrMemoryType.FuseBits, fusesData, 0, fusesSize); programmer.ReadPage(device.LockBits.StartAddress, device.LockBits.Location ?? AvrMemoryType.LockBits, locksData, 0, locksSize); } } op.CurrentState = "Everything is done"; EepromHexBoard = HexBoard.From(eepData); FlashHexBoard = HexBoard.From(flashData); FusesHexBoard = HexBoard.From(fusesData, device.FuseBits.StartAddress); LocksHexBoard = HexBoard.From(locksData, device.LockBits.StartAddress); return(true); }
public void SplitSuperPagesMaxTest() { var board = new HexBoard(); board[0x04] = 0x50; board[0x0c] = 0x30; board[0x10] = 0x10; board[0x17] = 0x20; board[0x24] = 0xd0; board[0x2c] = 0xb0; board[0x30] = 0x90; board[0x37] = 0xa0; var blocks = board.SplitBlocks(0x08); Assert.AreEqual(2, blocks.Blocks.Count); var firstBlock = blocks.Blocks[0]; var secondBlock = blocks.Blocks[1]; Assert.AreEqual(0x00, firstBlock.Address); Assert.AreEqual(0x20, secondBlock.Address); Assert.AreEqual(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x30, 0xff, 0xff, 0xff, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x20 }, firstBlock.Data); Assert.AreEqual(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0 }, secondBlock.Data); }
public FlasherModel() { FlashHexBoard = new HexBoard(); EepromHexBoard = new HexBoard(); FusesHexBoard = new HexBoard(); LocksHexBoard = new HexBoard(); }
public void ApplyTo(HexBoard board) { foreach (var gr in _groups) { gr.ApplyTo(board); } }
public void ApplyFrom(HexBoard data) { foreach (var gr in _groups) { gr.ApplyFrom(data); } }
private static void PlayFourMoves(HexBoard board) { board.PlayMove(2, 0, true); // playerX board.PlayMove(0, 2, false); // PlayerY board.PlayMove(2, 4, true); // playerX board.PlayMove(4, 2, false); // PlayerY }
private static void PlayerScorePartBarricade(IPathLengthFactory pathLengthFactory) { HexBoard hexBoard = new HexBoard(BoardSize); PathLengthBase pathLength = pathLengthFactory.CreatePathLength(hexBoard); // partly baricaded board for (int y = 0; y < hexBoard.Size; y++) { if ((y % 2) == 0) { hexBoard.PlayMove(2, y, true); } } int xScore = pathLength.PlayerScore(true); Assert.IsTrue(xScore > 0); int yScore = pathLength.PlayerScore(false); Assert.IsTrue(yScore > xScore); // some advantage to player 1 int advantageMoveScore = pathLength.SituationScore(); Assert.IsTrue(advantageMoveScore > 0); }
public void GetAgainDoesNotIncreaseCount() { BoardCache boardCache = new BoardCache(10); const int TestSize = 10; HexBoard[] usedBoards = new HexBoard[TestSize]; // add some boards for (int i = 0; i < TestSize; i++) { usedBoards[i] = boardCache.GetBoard(); } // remove them for (int i = 0; i < TestSize; i++) { boardCache.Release(usedBoards[i]); } // get again, count should not change since there are now boards ready to use for (int i = 0; i < TestSize; i++) { usedBoards[i] = boardCache.GetBoard(); Assert.IsNotNull(usedBoards[i]); Assert.AreEqual(TestSize, boardCache.BoardCount); } }
public PathLengthBase CreatePathLength(HexBoard board) { return new PathLengthAStar(board) { UseNeighbours2 = true }; }
public void BoardNeighboursTest() { HexBoard hexBoard = new HexBoard(BoardSize); for (int x = 0; x < hexBoard.Size; x++) { for (int y = 0; y < hexBoard.Size; y++) { Cell cell = hexBoard.GetCellAt(x, y); var neigbours = hexBoard.Neighbours(cell); Assert.IsNotNull(neigbours); /* all cells have at least 2 neighbours, and at most 6 */ Assert.GreaterOrEqual(neigbours.Length, 2); Assert.LessOrEqual(neigbours.Length, 6); /* cells not on the edge will have 6 neighbours */ if ((x > 0) && (y > 0) && (x < (hexBoard.Size - 1)) && (y < (hexBoard.Size - 1))) { Assert.AreEqual(neigbours.Length, 6); } NoNullsInCellArray(neigbours); foreach (Cell neibCell in neigbours) { DoTestNeighbour(cell, neibCell, hexBoard); } } } }
public void BoardNeighbours2Test() { HexBoard hexBoard = new HexBoard(BoardSize); for (int x = 0; x < hexBoard.Size; x++) { for (int y = 0; y < hexBoard.Size; y++) { Cell cell = hexBoard.GetCellAt(x, y); var neigbours2 = hexBoard.Neighbours2(cell); Assert.IsNotNull(neigbours2); /* all cells have at least 1 neighbours, and at most 6 */ Assert.Greater(neigbours2.GetLength(0), 0); Assert.Less(neigbours2.GetLength(0), 7); foreach (Cell[] triplet in neigbours2) { TestNeighbour2Triplet(cell, triplet); } } } }
public PathLengthBase CreatePathLength(HexBoard board) { return(new PathLengthAStar(board) { UseNeighbours2 = true }); }
public void Move(int dq, int dr) { q += dq; r += dr; //Todo: This should initiate or queue move animation rather than Translate. transform.Translate(HexBoard.GetXYZ(dq, dr), Space.Self); }
//String _imgPath; public TerrainGridHex(HexBoard<MapGridHex> board, HexCoords coords, String type, String imgSummer, String imgWinter, double stepCost, int elevation, List<Resource> resources) : base(board, coords) { Type = type; _specialType = ""; _stepCost = stepCost; _elevation = elevation; IsSummer = true; Resources = resources; //TODO: improve logic while (_bmpSummer == null) { try { _bmpSummer = new Bitmap(imgSummer); } catch (OutOfMemoryException) { } } while (_bmpWinter == null) { try { _bmpWinter = new Bitmap(imgWinter); } catch (OutOfMemoryException) { } } }
private static void PlayerScoreZigZag(IPathLengthFactory pathLengthFactory) { HexBoard hexBoard = new HexBoard(BoardSize); PathLengthBase pathLength = pathLengthFactory.CreatePathLength(hexBoard); for (int y = 0; y < hexBoard.Size - 1; y++) { hexBoard.PlayMove(2, y, true); hexBoard.PlayMove(5, hexBoard.Size - (1 + y), true); int xScore = pathLength.PlayerScore(true); Assert.IsTrue(xScore > 0); int yScore = pathLength.PlayerScore(false); Assert.IsTrue(yScore >= hexBoard.Size); if (y > (hexBoard.Size / 2)) { Assert.IsTrue(yScore > xScore); } // some advantage to player 1 int advantageMoveScore = pathLength.SituationScore(); Assert.IsTrue(advantageMoveScore >= y); } }
public void CopyFailTest() { HexBoard sourceBoard = new HexBoard(4); HexBoard copyBoard = new HexBoard(5); copyBoard.CopyStateFrom(sourceBoard); }
private static void PlayToWinInOneMove(HexBoard board, bool playerX) { // one move at 0,4 to win board.PlayMove(4, 0, playerX); board.PlayMove(3, 1, playerX); board.PlayMove(2, 2, playerX); board.PlayMove(1, 3, playerX); }
public HexBoardElement(int size) { _hexBoard = new HexBoard(size); _hexBoard.BoardReset += new EventHandler(_hexBoard_BoardReset); _boardButtons = new Button[size * size]; _decorations = new ContentControl[(_hexBoard.Size - 1) * 4]; }
public void ConstructorSetsProperties() { HexBoard hexBoard = new HexBoard(BoardSize); Assert.IsNotNull(hexBoard); Assert.AreEqual(BoardSize, hexBoard.Size); Assert.AreEqual(0, hexBoard.MovesPlayedCount); }
public void MovesPlayedCountIncrementsAfterMove() { HexBoard hexBoard = new HexBoard(BoardSize); Assert.AreEqual(0, hexBoard.MovesPlayedCount); hexBoard.PlayMove(1, 1, true); Assert.AreEqual(1, hexBoard.MovesPlayedCount); }
public void DuplicatePlayTest() { HexBoard hexBoard = new HexBoard(BoardSize); // set a cell hexBoard.PlayMove(1, 1, true); hexBoard.PlayMove(1, 1, true); }
public void BetweenEdgeTest() { HexBoard hexBoard = new HexBoard(BoardSize); for (int x = 0; x < hexBoard.Size; x++) { for (int y = 0; y < hexBoard.Size; y++) { Location testLoc = new Location(x, y); Cell[] resultX = hexBoard.BetweenEdge(testLoc, true); if (y == 1) { // second or second-last row if (x < hexBoard.Size - 1) { Assert.AreEqual(2, resultX.Length, testLoc.ToString()); } } else if (y == hexBoard.Size - 2) { // second or second-last row if (x > 0) { Assert.AreEqual(2, resultX.Length, testLoc.ToString()); } } else { Assert.AreEqual(0, resultX.Length, testLoc.ToString()); } Cell[] resultY = hexBoard.BetweenEdge(testLoc, false); if (x == 1) { // second or second-last row if (y < hexBoard.Size - 1) { Assert.AreEqual(2, resultY.Length, testLoc.ToString()); } } else if (x == hexBoard.Size - 2) { // second or second-last row if (y > 0) { Assert.AreEqual(2, resultY.Length, testLoc.ToString()); } } else { Assert.AreEqual(0, resultY.Length, testLoc.ToString()); } } } }
public void ApplyTo(HexBoard board) { foreach (var bit in _bits) { var val = board[bit.Address] ?? 0; val = bit.Apply(val); board[bit.Address] = val; } }
public void CountEmptyTest() { CandidateMovesAll allMoves = new CandidateMovesAll(); HexBoard testBoard = new HexBoard(BoardSize); Location[] moves = allMoves.CandidateMoves(testBoard, 0).ToArray(); Assert.AreEqual(BoardCellCount, moves.Length); }
public Minimax(HexBoard board, GoodMoves goodMoves, ICandidateMoves candidateMovesFinder) { this.actualBoard = board; this.goodMoves = goodMoves; this.candidateMovesFinder = candidateMovesFinder; this.boardCache = new BoardCache(board.Size); this.pathLengthFactory = new PathLengthAStarFactory(); }
public void TestEqualsFail() { HexBoard hexBoard = new HexBoard(BoardSize); Assert.IsFalse(hexBoard.Equals(null)); Assert.IsFalse(hexBoard.Equals(3)); Assert.IsFalse(hexBoard.Equals("Hello hex board")); Assert.IsFalse(hexBoard.Equals(new HexBoard(3))); }
private static void PlayTwoMoves(HexBoard playBoard) { // best move (and winning move ) is the middle (1,1) or corner (0, 2) // but it takes lookahead or 3 or more to see that // Should be quick to calc since there's only 9 cells // Search tree is not broad, we can go deep playBoard.PlayMove(1, 0, true); // PlayerX playBoard.PlayMove(2, 1, false); // PlayerY }
private static MapGridHex InitializeHex(HexBoard <MapGridHex> board, HexCoords coords) { switch (_board[coords.User.Y][coords.User.X]) { case '.': return(new PathMazeGridHex(board, coords)); default: return(new WallMazeGridHex(board, coords)); } }
private static void PlayFourMoves(HexBoard playBoard) { // set up so the best move should be that the middle - a winning move for either player // can see this just looking at one move playBoard.PlayMove(1, 0, true); // PlayerX playBoard.PlayMove(2, 1, false); // PlayerY playBoard.PlayMove(0, 1, false); // PlayerX playBoard.PlayMove(1, 2, true); // PlayerY }
/// <summary> /// Initializes a new instance of the HexGame class, with a board size /// </summary> /// <param name="boardSize">size of the board</param> public HexGame(int boardSize) { this.board = new HexBoard(boardSize); IPathLengthFactory pathLengthFactory = new PathLengthAStarFactory(); this.xPathLength = pathLengthFactory.CreatePathLength(this.board); this.yPathLength = pathLengthFactory.CreatePathLength(this.board); this.goodMoves = new GoodMoves(); this.goodMoves.DefaultGoodMoves(boardSize, 5); }
public HexBoardElement(int size) { _hexBoard = new HexBoard(size); _hexBoard.BoardReset += delegate(object sender, EventArgs e) { setData(); }; _boardButtons = new Button[size * size]; _decorations = new ContentControl[(_hexBoard.Size - 1) * 4]; }
public void LoadInitialize(string name) { DestroyBoard(); myBoard = LoadBoard(name); myBoard.Initialize(tileList); }
public void newBoard(int x, int y) { float temp = Time.realtimeSinceStartup; myBoard = new HexBoard(x, y, tileList); myBoard.SetSizes(tileList.hexagon); myBoard.BuildBoard(); Debug.Log("New Board Created in " + (Time.realtimeSinceStartup - temp) + "secs. (" + x + ", " + y + ")"); }
/// <summary>TODO</summary> protected MapGridHex(HexBoard<MapGridHex> board, HexCoords coords) : base(board, coords) { ((IMapGridHex)this).Board = board; }
public void Start() { HexBoard = GetComponent<HexBoard>(); }
/// <summary>Set up and generate the Board.</summary> void Start() { float startemp = Time.realtimeSinceStartup; // Try loading the last board saved. if (lastBoardSaved != null && lastBoardSaved.Length > 0) myBoard = LoadBoard(lastBoardSaved); // If no board was loaded, make a new one. // Else initialize the loaded board. TODO: Change to Build. if (myBoard == null) { newBoard(20, 20); } else { myBoard.Initialize(tileList); } Debug.Log("Start() over, " + (Time.realtimeSinceStartup - startemp) + "secs."); var tmp = Loom.Current; }
public PositionControl(HexCoord position, HexBoard hexBoard) { //cellColoring = (GameObject) Instantiate(sampleCellColored, new Vector3(position.x, 0.01f , position.z), sampleCellColored.transform.rotation); // TODO: show controlled field Position = position; HexBoard = hexBoard; }
public void Start() { HexBoard = GetComponent<HexBoard>(); Positions = GetComponent<GridPositionElements>(); }