Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I got my code to setup a normal marble solitaire board withthe code below: /** * This method initializes/sets up the game board in a
I got my code to setup a normal marble solitaire board withthe code below:
/** * This method initializes/sets up the game board in a 2D array. * * @param sRow the empty row for initial position * @param sCol the empty column for initial position * @return true-if sRow,sCol are correct and the board could be initialized, false-otherwise */protected SlotState[][] setUpBoard(int sRow, int sCol) { int dimensionOfBoard = getBoardSize(); SlotState[][] board = new SlotState[dimensionOfBoard][dimensionOfBoard]; for (int row = 0; row < board.length; row++) { for (int col = 0; col < board[row].length; col++) { // checks for invalid slots if (((row >= 0 && ((row <= (this.arm - 1) || (row > (this.arm * 2) - 2 && row < dimensionOfBoard)))) && (col >= (this.arm - 1) && col < (this.arm * 2) - 1)) || ((col >= 0 && col < dimensionOfBoard) && (row >= this.arm - 1 && row < ((this.arm * 2) - 1)))) { if (sRow == row && sCol == col) { board[row][col] = SlotState.Empty; } else { board[row][col] = SlotState.Marble; } } //checks for out of bounds else { if (sRow == row && sCol == col) { throw new IllegalArgumentException("Cannot make empty slot"); } else { board[row][col] = SlotState.Invalid; } } } } return board;}
The code above sets up the board to print:
" O O O" + " O O O" + "O O O O O O O" + "O O O _ O O O" + "O O O O O O O" + " O O O" + " O O O"
Now I want to set up a TRIANGLE solitaire board. Please help, Idon't know how to. I would love if you used some of the code fromabove to assist with creating a Triangle Solitaire board.
It should print:
" _" + " O O" + " O O O" + " O O O O" + " O O O O O" + " O O O O O O" + "O O O O O O O"
Step by Step Solution
★★★★★
3.49 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
i have done this proect before and there is the code hope it will help algorithm used in this peg s...
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started