File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes How to populate the board for chess game Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "How to populate the board for chess game" Watch "How to populate the board for chess game" New topic
Author

How to populate the board for chess game

J burke
Greenhorn

Joined: Jun 21, 2011
Posts: 1
Im a beginner in groovy and Im working on simple chess game with board size 8 rows on 3 colums to hold red and blue pawns positions.
At the moment Im stuck with positioning the pawns on the board. i need to put red pawns on the top of column, and blue in the bottom ie:
i (1,1)(1,2)(1,3)
j (8,1)(8,2)(8,3)

I will appreciate any suggestion, this is what I've done so far:

def a = new Object [8][3]
def val = new Object [24]

val= [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]

val[1,1] = "R"
val[1,2] = "R"
val[1,3] = "R"
val[8,1] = "B"
val[8,2] = "B"
val[8,3] = "B"

int valIndex = 0

for (i in 0..7) {
for (j in 0..2) {
a[i][j] = " "
}
}

println (" 1 2 3 ")
println (" -------------")
for (i in 0..7) {
print (i+1)
print (" ")
for (j in 0..2) {
a[i][j] = val[valIndex]
valIndex++
printf ("| %s ", a[i][j])
}
println("| ")
println (" -------------")
}


or maybe without values

def a = new Object [8][3]
for (i in 0..7) {
for (j in 0..2) {
a[i][j] = " "
}
}


println (" 1 2 3 ")
println (" -------------")
for (i in 0..7) {
print (i+1)
print (" ")
for (j in 0..2) {
printf ("| %s ", a[i][j])
}
println("| ")
println (" -------------")
}

thanks in advance for any help,
groovy newbie
 
 
subject: How to populate the board for chess game
 
Threads others viewed
Convert Into Java Code.
loop
Just wanted to share my code SudokuSolver !
Example of using Groovy Closure for a different programming style
Project Euler problems with Scala
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture