func (g *Game) placeBlock(x int, y int, block [][]BoardElement) error {
	if x < 0 || y < 0 {
		return &ErrorGame{IncorrectPosition, fmt.Sprintf("%d,%d is below 0,0", x, y)}
	}

	newBoard := make([][]BoardElement, len(g.Board))
	for i := range g.Board {
		newBoard[i] = make([]BoardElement, len(g.Board[i]))
		copy(newBoard[i], g.Board[i])
	}

	placementScore := 0

	for boardX := x; boardX < x+len(block); boardX++ {
		for boardY := y; boardY < y+len(block); boardY++ {
			blockX := boardX - x
			blockY := boardY - y
			if boardX >= len(newBoard) || boardY >= len(newBoard) {
				if block[blockX][blockY] != None {
					return &ErrorGame{IncorrectPosition, fmt.Sprintf("%d,%d is out of board and block at %d,%d is not empty (%d)", boardX, boardY, blockX, blockY, block[blockX][blockY])}
				}
				continue
			}
			if newBoard[boardX][boardY] == None {
				newBoard[boardX][boardY] = block[blockX][blockY]
				if block[blockX][blockY] != None {
					placementScore++
				}
			} else if block[blockX][blockY] != None {
				return &ErrorGame{IncorrectPosition, fmt.Sprintf("board at %d,%d is not empty (%d) and block at %d,%d is also not empty (%d)", boardX, boardY, newBoard[boardX][boardY], blockX, blockY, block[blockX][blockY])}
			}
		}
	}

	fullLanesScore := checkAndRemoveFullLanes(newBoard)

	g.Board = newBoard
	g.Score += placementScore + fullLanesScore
	return nil
}
// placeBlock places provided block on the board at x and y position being 0,0 block's position.
// In case the placement is not possible error is returned.
placeBlock places provided block on the board at x and y position being 0,0 block's position.
In case the placement is not possible error is returned.
// placeBlock places provided block on the board at x and y position being 0 0 block ' s position . // In case the placement is not possible error is returned .
func (g *Game) placeBlock(x int, y int, block [][]BoardElement) error {
	if x < 0 || y < 0 {
		return &ErrorGame{IncorrectPosition, fmt.Sprintf("%d,%d is below 0,0", x, y)}
	}
	newBoard := make([][]BoardElement, len(g.Board))
	for i := range g.Board {
		newBoard[i] = make([]BoardElement, len(g.Board[i]))
		copy(newBoard[i], g.Board[i])
	}
	placementScore := 0
	for boardX := x; boardX < x+len(block); boardX++ {
		for boardY := y; boardY < y+len(block); boardY++ {
			blockX := boardX - x
			blockY := boardY - y
			if boardX >= len(newBoard) || boardY >= len(newBoard) {
				if block[blockX][blockY] != None {
					return &ErrorGame{IncorrectPosition, fmt.Sprintf("%d,%d is out of board and block at %d,%d is not empty (%d)", boardX, boardY, blockX, blockY, block[blockX][blockY])}
				}
				continue
			}
			if newBoard[boardX][boardY] == None {
				newBoard[boardX][boardY] = block[blockX][blockY]
				if block[blockX][blockY] != None {
					placementScore++
				}
			} else if block[blockX][blockY] != None {
				return &ErrorGame{IncorrectPosition, fmt.Sprintf("board at %d,%d is not empty (%d) and block at %d,%d is also not empty (%d)", boardX, boardY, newBoard[boardX][boardY], blockX, blockY, block[blockX][blockY])}
			}
		}
	}
	fullLanesScore := checkAndRemoveFullLanes(newBoard)
	g.Board = newBoard
	g.Score += placementScore + fullLanesScore
	return nil
}
func ( g * Game ) placeBlock ( x int , y int , block [ ] [ ] BoardElement ) error { if x < 0 || y < 0 { return & ErrorGame { IncorrectPosition , fmt . Sprintf ( " " , x , y ) } } newBoard := make ( [ ] [ ] BoardElement , len ( g . Board ) ) for i := range g . Board { newBoard [ i ] = make ( [ ] BoardElement , len ( g . Board [ i ] ) ) copy ( newBoard [ i ] , g . Board [ i ] ) } placementScore := 0 for boardX := x ; boardX < x + len ( block ) ; boardX ++ { for boardY := y ; boardY < y + len ( block ) ; boardY ++ { blockX := boardX - x blockY := boardY - y if boardX >= len ( newBoard ) || boardY >= len ( newBoard ) { if block [ blockX ] [ blockY ] != None { return & ErrorGame { IncorrectPosition , fmt . Sprintf ( " " , boardX , boardY , blockX , blockY , block [ blockX ] [ blockY ] ) } } continue } if newBoard [ boardX ] [ boardY ] == None { newBoard [ boardX ] [ boardY ] = block [ blockX ] [ blockY ] if block [ blockX ] [ blockY ] != None { placementScore ++ } } else if block [ blockX ] [ blockY ] != None { return & ErrorGame { IncorrectPosition , fmt . Sprintf ( " " , boardX , boardY , newBoard [ boardX ] [ boardY ] , blockX , blockY , block [ blockX ] [ blockY ] ) } } } } fullLanesScore := checkAndRemoveFullLanes ( newBoard ) g . Board = newBoard g . Score += placementScore + fullLanesScore return nil }
placeBlock places provided block on the board at x and y position being 0,0 block's position.
placeBlock places provided block on the board at x and y position being 0 0 block ' s position .