|
|
@@ -51,8 +51,8 @@ func NewRemote(width, height int) *Board {
|
|
|
|
|
|
log.Printf("Start creating board %v x %v", width, height)
|
|
|
|
|
|
- regionWidth := 8
|
|
|
- regionHeight := 8
|
|
|
+ regionWidth := 16
|
|
|
+ regionHeight := 16
|
|
|
|
|
|
regionWidthNum := width / regionWidth
|
|
|
regionHeightNum := height / regionHeight
|
|
|
@@ -64,30 +64,33 @@ func NewRemote(width, height int) *Board {
|
|
|
x := i * regionWidth
|
|
|
y := j * regionHeight
|
|
|
|
|
|
- gbt := req{
|
|
|
+ region := req{
|
|
|
x: x,
|
|
|
y: y,
|
|
|
width: regionWidth,
|
|
|
height: regionHeight,
|
|
|
}
|
|
|
- go b.genRegion(gbt, returnChan)
|
|
|
+ go b.genRegion(region, returnChan)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
answers := 0
|
|
|
- for regionWidthNum+regionHeightNum > answers {
|
|
|
+ for regionWidthNum*regionHeightNum > answers {
|
|
|
|
|
|
result := <-returnChan
|
|
|
|
|
|
- n := -1
|
|
|
-
|
|
|
- for n != 0 {
|
|
|
- index := result.x*b.Width + result.y
|
|
|
+ fmt.Printf("Received partial: x=%v, y=%v", result.x, result.y)
|
|
|
+ for ry := 0; ry < regionHeight; ry++ {
|
|
|
+ index := result.x + (result.y+ry)*b.Width
|
|
|
+ fmt.Printf("index=%v\n", index)
|
|
|
i := index / 4 // tiles per byte
|
|
|
-
|
|
|
- // TODO
|
|
|
- ba := b.data[i : i+regionWidth/4]
|
|
|
- n, _ = result.boardTile.Read(ba)
|
|
|
+ ba := make([]byte, regionWidth/4)
|
|
|
+ result.boardTile.Read(ba)
|
|
|
+ for _, v := range ba {
|
|
|
+ fmt.Printf("%b ", v)
|
|
|
+ }
|
|
|
+ fmt.Println()
|
|
|
+ copy(b.data[i:i+regionWidth/4], ba)
|
|
|
}
|
|
|
answers++
|
|
|
}
|
|
|
@@ -104,14 +107,14 @@ func NewRemote(width, height int) *Board {
|
|
|
return b
|
|
|
}
|
|
|
|
|
|
-func (b *Board) genRegion(req req, responseChan chan response) {
|
|
|
- requestUrl := fmt.Sprintf("http://localhost:8081/?totalWidth=%v&totalHeight=%vwidth=%v&height=%v&x=%v&y=%v", b.Width, b.Height, req.width, req.height, req.x, req.y)
|
|
|
+func (b *Board) genRegion(region req, responseChan chan response) {
|
|
|
+ requestUrl := fmt.Sprintf("http://localhost:8081/?totalWidth=%v&totalHeight=%v&width=%v&height=%v&x=%v&y=%v", b.Width, b.Height, region.width, region.height, region.x, region.y)
|
|
|
log.Printf("Requested generation of tile with url: %v\n", requestUrl)
|
|
|
resp, _ := http.Get(requestUrl)
|
|
|
|
|
|
result := response{
|
|
|
- x: req.x,
|
|
|
- y: req.y,
|
|
|
+ x: region.x,
|
|
|
+ y: region.y,
|
|
|
boardTile: resp.Body,
|
|
|
}
|
|
|
|