@@ -29,7 +29,7 @@ type rotationCompass [4]rotationSet
29
29
// If the first coordinate cannot be used the next will be attempted.
30
30
// This continues until there are no more coordinates to fall back on (in which case rotation is not possible).
31
31
// This is part of the Super Rotation System (SRS).
32
- type rotationSet []Coordinate
32
+ type rotationSet []* Coordinate
33
33
34
34
// RotationCompasses is a map of Tetrimino values to the coordinates used for rotation.
35
35
// Each slice should contain a coordinate for north, east, south, and west in that order.
@@ -324,23 +324,28 @@ func (t *Tetrimino) rotateCounterClockwise(matrix Matrix) (bool, error) {
324
324
325
325
t .transpose ()
326
326
327
- var err error
328
- t .CompassDirection , err = positiveMod (t .CompassDirection + 1 , len (t .RotationCompass ))
329
- if err != nil {
330
- return false , fmt .Errorf ("failed to get positive mod: %w" , err )
331
- }
332
-
327
+ foundValid := false
333
328
originalX , originalY := t .Pos .X , t .Pos .Y
334
329
for _ , coord := range t .RotationCompass [t .CompassDirection ] {
335
330
t .Pos .X = originalX - coord .X
336
331
t .Pos .Y = originalY - coord .Y
337
332
338
333
if t .isValid (matrix ) {
339
- return true , nil
334
+ foundValid = true
335
+ break
340
336
}
341
337
}
338
+ if ! foundValid {
339
+ return false , nil
340
+ }
342
341
343
- return false , nil
342
+ var err error
343
+ t .CompassDirection , err = positiveMod (t .CompassDirection - 1 , len (t .RotationCompass ))
344
+ if err != nil {
345
+ return false , fmt .Errorf ("failed to get positive mod: %w" , err )
346
+ }
347
+
348
+ return true , nil
344
349
}
345
350
346
351
func (t * Tetrimino ) transpose () {
0 commit comments