You are viewing a single comment's thread. Return to all comments →
I wrote a c# struct that saves the board state, and allows you to add an obstacle and modify the movable spaces based on the current state.
{ BoardConfig boardConfig = new BoardConfig(r_q, c_q, n); for(int i = 0; i < k; ++i) { boardConfig.AddObsticle(obstacles[i]); } return boardConfig.GetMaxMoves(); } private struct BoardConfig { public int RowIndex { get; private set; } public int ColumnIndex { get; private set; } public int BorderMax { get; private set; } public int BorderMin { get; private set; } public int LeftMax { get; private set; } public int RightMax { get; private set; } public int UpMax { get; private set; } public int DownMax { get; private set; } public int UpRightMax { get; private set; } public int UpLeftMax { get; private set; } public int DownLeftMax { get; private set; } public int DownRightMax { get; private set; } public BoardConfig(int queenRow, int queenColumn, int boardSize) { RowIndex = queenRow - 1; ColumnIndex = queenColumn - 1; BorderMax = boardSize - 1; BorderMin = 0; LeftMax = Math.Max(ColumnIndex, BorderMin); RightMax = BorderMax - Math.Min(ColumnIndex, BorderMax); UpMax = BorderMax - Math.Min(RowIndex, BorderMax); DownMax = Math.Max(RowIndex, BorderMin); UpRightMax = Math.Min(UpMax, RightMax); UpLeftMax = Math.Min(UpMax, LeftMax); DownLeftMax = Math.Min(DownMax, LeftMax); DownRightMax = Math.Min(DownMax, RightMax); } public void Print() { Console.WriteLine("RowIndex: " + RowIndex); Console.WriteLine("ColumnIndex: " + ColumnIndex); Console.WriteLine("BorderMax: " + BorderMax); Console.WriteLine("BorderMin: " + BorderMin); Console.WriteLine("LeftMax: " + LeftMax); Console.WriteLine("RightMax: " + RightMax); Console.WriteLine("UpMax: " + UpMax); Console.WriteLine("DownMax: " + DownMax); Console.WriteLine("UpRightMax: " + UpRightMax); Console.WriteLine("UpLeftMax: " + UpLeftMax); Console.WriteLine("DownLeftMax: " + DownLeftMax); Console.WriteLine("DownRightMax: " + DownRightMax); } public void AddObsticle(List<int> obstacle) { int x, y; y = obstacle[0] - 1; x = obstacle[1] - 1; if(RowIndex == y) { CheckLeftRightMax(x); } else if(ColumnIndex == x) { CheckUpDownMax(y); } else { CheckDiagonals(x, y); } } private void CheckLeftRightMax(int obstacleX) { if(obstacleX > ColumnIndex) { RightMax = Math.Min(RightMax, obstacleX - 1 - ColumnIndex); } else { LeftMax = Math.Min(LeftMax, ColumnIndex - 1 - obstacleX); } } private void CheckUpDownMax(int obstacleY) { if(obstacleY > RowIndex) { UpMax = Math.Min(UpMax, obstacleY - 1 - RowIndex); } else { DownMax = Math.Min(DownMax, RowIndex - 1 - obstacleY); } } private void CheckDiagonals(int obstacleX, int obstacleY) { int difX = obstacleX - ColumnIndex; int difY = obstacleY - RowIndex; if(Math.Abs(difX) == Math.Abs(difY)) { int dist = Math.Abs(difX) - 1; if(difX > 0) { if(difY > 0) // Up Right { UpRightMax = Math.Min(UpRightMax, dist); } else // Down Right { DownRightMax = Math.Min(DownRightMax, dist); } } else { if(difY > 0) // Up Left { UpLeftMax = Math.Min(UpLeftMax, dist); } else // Down Left { DownLeftMax = Math.Min(DownLeftMax, dist); } } } } public int GetMaxMoves() { return LeftMax + RightMax + UpMax + DownMax + UpRightMax + UpLeftMax + DownLeftMax + DownRightMax; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queen's Attack II
You are viewing a single comment's thread. Return to all comments →
I wrote a c# struct that saves the board state, and allows you to add an obstacle and modify the movable spaces based on the current state.