Only keep consecutive rowClears
This commit is contained in:
		
							parent
							
								
									dcacb9bf73
								
							
						
					
					
						commit
						7b82d01dd1
					
				
					 1 changed files with 17 additions and 16 deletions
				
			
		| 
						 | 
					@ -17,9 +17,9 @@ import Data.Maybe (fromMaybe)
 | 
				
			||||||
import Data.Monoid (First(..))
 | 
					import Data.Monoid (First(..))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- TODO
 | 
					-- TODO
 | 
				
			||||||
--   1. prune rowClears on zero
 | 
					 | 
				
			||||||
--   2. make sure argument orders make sense
 | 
					 | 
				
			||||||
--   3. possibly add 'user' to game state to draw name entry from UI.Game
 | 
					--   3. possibly add 'user' to game state to draw name entry from UI.Game
 | 
				
			||||||
 | 
					--   4. sometimes freezes if manually shifting down while freezing
 | 
				
			||||||
 | 
					--   5. implement hard drop with spacebar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Types and instances
 | 
					-- Types and instances
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,7 @@ timeStep g = if (blockStopped g)
 | 
				
			||||||
-- TODO check if mapKeysMonotonic works
 | 
					-- TODO check if mapKeysMonotonic works
 | 
				
			||||||
clearFullRows :: Game -> Game
 | 
					clearFullRows :: Game -> Game
 | 
				
			||||||
clearFullRows g = g & board %~ clearBoard
 | 
					clearFullRows g = g & board %~ clearBoard
 | 
				
			||||||
                    & rowClears %~ (|> rowCount)
 | 
					                    & rowClears %~ (addToRowClears rowCount)
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
    clearBoard            = M.mapKeys shiftCoordAbove . M.filterWithKey notInFullRow
 | 
					    clearBoard            = M.mapKeys shiftCoordAbove . M.filterWithKey notInFullRow
 | 
				
			||||||
    notInFullRow (_,y) _  = y `notElem` fullRowIndices
 | 
					    notInFullRow (_,y) _  = y `notElem` fullRowIndices
 | 
				
			||||||
| 
						 | 
					@ -188,16 +188,22 @@ updateScore :: Game -> Game
 | 
				
			||||||
updateScore g = g & score %~ (+ newPoints)
 | 
					updateScore g = g & score %~ (+ newPoints)
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
    newPoints = (1 + g ^. level) * (g ^. rowClears ^. to latestOrZero ^. to points)
 | 
					    newPoints = (1 + g ^. level) * (g ^. rowClears ^. to latestOrZero ^. to points)
 | 
				
			||||||
 | 
					    points 0  = 0
 | 
				
			||||||
 | 
					    points 1  = 40
 | 
				
			||||||
 | 
					    points 2  = 100
 | 
				
			||||||
 | 
					    points 3  = 300
 | 
				
			||||||
 | 
					    points n  = 800
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Points awarded from number of rows cleared
 | 
					-- | Empties row on 0, otherwise appends value (just keeps consecutive information)
 | 
				
			||||||
points :: Int -- ^ rows cleared
 | 
					addToRowClears :: Int -> Seq.Seq Int -> Seq.Seq Int
 | 
				
			||||||
       -> Int -- ^ resulting points
 | 
					addToRowClears 0 _  = mempty
 | 
				
			||||||
points 0 = 0
 | 
					addToRowClears n rs = rs |> n
 | 
				
			||||||
points 1 = 40
 | 
					 | 
				
			||||||
points 2 = 100
 | 
					 | 
				
			||||||
points 3 = 300
 | 
					 | 
				
			||||||
points n = 800
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- | Get last value of sequence or 0 if empty
 | 
				
			||||||
 | 
					latestOrZero :: Seq.Seq Int -> Int
 | 
				
			||||||
 | 
					latestOrZero = go . Seq.viewr
 | 
				
			||||||
 | 
					  where go EmptyR = 0
 | 
				
			||||||
 | 
					        go (_ :> n) = n
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Handle counterclockwise block rotation (if possible)
 | 
					-- | Handle counterclockwise block rotation (if possible)
 | 
				
			||||||
-- Allows wallkicks: http://tetris.wikia.com/wiki/TGM_rotation
 | 
					-- Allows wallkicks: http://tetris.wikia.com/wiki/TGM_rotation
 | 
				
			||||||
| 
						 | 
					@ -270,8 +276,3 @@ shuffle xs
 | 
				
			||||||
      let (left, right) = Seq.splitAt randomPosition xs
 | 
					      let (left, right) = Seq.splitAt randomPosition xs
 | 
				
			||||||
          (y :< ys)     = Seq.viewl right
 | 
					          (y :< ys)     = Seq.viewl right
 | 
				
			||||||
      fmap (y <|) (shuffle $ left >< ys)
 | 
					      fmap (y <|) (shuffle $ left >< ys)
 | 
				
			||||||
 | 
					 | 
				
			||||||
latestOrZero :: Seq.Seq Int -> Int
 | 
					 | 
				
			||||||
latestOrZero = go . Seq.viewr
 | 
					 | 
				
			||||||
  where go EmptyR = 0
 | 
					 | 
				
			||||||
        go (_ :> n) = n
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue