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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to populate the board for chess game