From af1c09110f710563b9374414f517728dacf0931c Mon Sep 17 00:00:00 2001 From: Andrew Brogdon Date: Sat, 22 Feb 2025 14:44:23 -0800 Subject: [PATCH] Updated formatting. Thanks 3.7 --- lib/game_board.dart | 15 ++++--- lib/game_model.dart | 5 +-- lib/main.dart | 85 +++++++++++++++++-------------------- lib/move_finder.dart | 31 ++++++++------ lib/styling.dart | 29 +++---------- lib/thinking_indicator.dart | 56 +++++++++++------------- 6 files changed, 97 insertions(+), 124 deletions(-) diff --git a/lib/game_board.dart b/lib/game_board.dart index 8ed0b0e..fd89a2a 100644 --- a/lib/game_board.dart +++ b/lib/game_board.dart @@ -40,7 +40,7 @@ class GameBoard { /// Copy constructor. GameBoard.fromGameBoard(GameBoard other) - : rows = List.generate(height, (i) => List.from(other.rows[i])); + : rows = List.generate(height, (i) => List.from(other.rows[i])); /// Retrieves the type of piece at a location on the game board. PieceType getPieceAtLocation(int x, int y) { @@ -51,10 +51,7 @@ class GameBoard { /// Gets the total number of pieces of a particular type. int getPieceCount(PieceType pieceType) { - return rows.fold( - 0, - (s, e) => s + e.where((e) => e == pieceType).length, - ); + return rows.fold(0, (s, e) => s + e.where((e) => e == pieceType).length); } /// Calculates the list of available moves on this board for a player. These @@ -136,7 +133,13 @@ class GameBoard { // to true, the pieces are flipped in place to their new colors before the // method returns. bool _traversePath( - int x, int y, int dx, int dy, PieceType player, bool flip) { + int x, + int y, + int dx, + int dy, + PieceType player, + bool flip, + ) { var foundOpponent = false; var curX = x + dx; var curY = y + dy; diff --git a/lib/game_model.dart b/lib/game_model.dart index 411319b..8cff56d 100644 --- a/lib/game_model.dart +++ b/lib/game_model.dart @@ -10,10 +10,7 @@ class GameModel { late final GameBoard board; final PieceType player; - GameModel({ - required this.board, - this.player = PieceType.black, - }); + GameModel({required this.board, this.player = PieceType.black}); int get blackScore => board.getPieceCount(PieceType.black); diff --git a/lib/main.dart b/lib/main.dart index 17b8979..61b60f3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -40,8 +40,8 @@ class FlutterFlipApp extends StatelessWidget { onGenerateRoute: (settings) { return PageRouteBuilder( settings: settings, - pageBuilder: (context, animation, secondaryAnimation) => - const GameScreen(), + pageBuilder: + (context, animation, secondaryAnimation) => const GameScreen(), ); }, ); @@ -145,14 +145,16 @@ class GameScreenState extends State { Widget _buildScoreBox(PieceType player, GameModel model) { var label = player == PieceType.black ? 'black' : 'white'; - var scoreText = player == PieceType.black - ? '${model.blackScore}' - : '${model.whiteScore}'; + var scoreText = + player == PieceType.black + ? '${model.blackScore}' + : '${model.whiteScore}'; return DecoratedBox( - decoration: (model.player == player) - ? Styling.activePlayerIndicator - : Styling.inactivePlayerIndicator, + decoration: + (model.player == player) + ? Styling.activePlayerIndicator + : Styling.inactivePlayerIndicator, child: Column( children: [ Text( @@ -164,7 +166,7 @@ class GameScreenState extends State { scoreText, textAlign: TextAlign.center, style: Styling.scoreText, - ) + ), ], ), ); @@ -177,32 +179,34 @@ class GameScreenState extends State { final spots = []; for (var x = 0; x < GameBoard.width; x++) { - spots.add(AnimatedContainer( - duration: const Duration( - milliseconds: 500, - ), - margin: const EdgeInsets.all(1.0), - decoration: BoxDecoration( - gradient: - Styling.pieceGradients[model.board.getPieceAtLocation(x, y)], - ), - child: SizedBox( - width: 40.0, - height: 40.0, - child: GestureDetector( - onTap: () { - _attemptUserMove(model, x, y); - }, + spots.add( + AnimatedContainer( + duration: const Duration(milliseconds: 500), + margin: const EdgeInsets.all(1.0), + decoration: BoxDecoration( + gradient: + Styling.pieceGradients[model.board.getPieceAtLocation(x, y)], + ), + child: SizedBox( + width: 40.0, + height: 40.0, + child: GestureDetector( + onTap: () { + _attemptUserMove(model, x, y); + }, + ), ), ), - )); + ); } - rows.add(Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: spots, - )); + rows.add( + Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: spots, + ), + ); } return rows; @@ -214,16 +218,11 @@ class GameScreenState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - Text( - model.gameResultString, - style: Styling.resultText, - ), + Text(model.gameResultString, style: Styling.resultText), const SizedBox(height: 30), GestureDetector( onTap: () { - _restartController.add( - GameModel(board: GameBoard()), - ); + _restartController.add(GameModel(board: GameBoard())); }, child: Container( decoration: BoxDecoration( @@ -232,10 +231,7 @@ class GameScreenState extends State { ), child: const Padding( padding: EdgeInsets.fromLTRB(15, 5, 15, 9), - child: Text( - 'new game', - style: Styling.buttonText, - ), + child: Text('new game', style: Styling.buttonText), ), ), ), @@ -252,10 +248,7 @@ class GameScreenState extends State { gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, - colors: [ - Styling.backgroundStartColor, - Styling.backgroundFinishColor, - ], + colors: [Styling.backgroundStartColor, Styling.backgroundFinishColor], ), ), child: SafeArea( diff --git a/lib/move_finder.dart b/lib/move_finder.dart index 3392688..14ee7a7 100644 --- a/lib/move_finder.dart +++ b/lib/move_finder.dart @@ -33,7 +33,11 @@ class ScoredMove { // This is that method for [MoveFinder]. Position? _findNextMove(MoveSearchArgs args) { final bestMove = _performSearchPly( - args.board, args.player, args.player, args.numPlies - 1); + args.board, + args.player, + args.player, + args.numPlies - 1, + ); return bestMove?.move; } @@ -55,12 +59,16 @@ ScoredMove? _performSearchPly( ScoredMove? bestMove; for (var i = 0; i < availableMoves.length; i++) { - final newBoard = - board.updateForMove(availableMoves[i].x, availableMoves[i].y, player); + final newBoard = board.updateForMove( + availableMoves[i].x, + availableMoves[i].y, + player, + ); if (pliesRemaining > 0 && newBoard.getMovesForPlayer(player.opponent).isNotEmpty) { // Opponent has next turn. - score = _performSearchPly( + score = + _performSearchPly( newBoard, scoringPlayer, player.opponent, @@ -70,7 +78,8 @@ ScoredMove? _performSearchPly( } else if (pliesRemaining > 0 && newBoard.getMovesForPlayer(player).isNotEmpty) { // Opponent has no moves; player gets another turn. - score = _performSearchPly( + score = + _performSearchPly( newBoard, scoringPlayer, player, @@ -85,8 +94,10 @@ ScoredMove? _performSearchPly( if (bestMove == null || (score > bestMove.score && scoringPlayer == player) || (score < bestMove.score && scoringPlayer != player)) { - bestMove = - ScoredMove(score, Position(availableMoves[i].x, availableMoves[i].y)); + bestMove = ScoredMove( + score, + Position(availableMoves[i].x, availableMoves[i].y), + ); } } @@ -107,11 +118,7 @@ class MoveFinder { Future findNextMove(PieceType player, int numPlies) { return compute( _findNextMove, - MoveSearchArgs( - board: initialBoard, - player: player, - numPlies: numPlies, - ), + MoveSearchArgs(board: initialBoard, player: player, numPlies: numPlies), ); } } diff --git a/lib/styling.dart b/lib/styling.dart index 49dbd4b..070f4df 100644 --- a/lib/styling.dart +++ b/lib/styling.dart @@ -19,26 +19,17 @@ abstract class Styling { PieceType.black: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, - colors: [ - Color(0xff101010), - Color(0xff303030), - ], + colors: [Color(0xff101010), Color(0xff303030)], ), PieceType.white: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, - colors: [ - Color(0xffffffff), - Color(0xffe0e0e0), - ], + colors: [Color(0xffffffff), Color(0xffe0e0e0)], ), PieceType.empty: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, - colors: [ - Color(0x60ffffff), - Color(0x40ffffff), - ], + colors: [Color(0x60ffffff), Color(0x40ffffff)], ), }; @@ -89,20 +80,10 @@ abstract class Styling { // **** BOXES **** static const activePlayerIndicator = BoxDecoration( - border: Border( - bottom: BorderSide( - width: 2.0, - color: Color(0xffffffff), - ), - ), + border: Border(bottom: BorderSide(width: 2.0, color: Color(0xffffffff))), ); static const inactivePlayerIndicator = BoxDecoration( - border: Border( - bottom: BorderSide( - width: 2.0, - color: Color(0x00000000), - ), - ), + border: Border(bottom: BorderSide(width: 2.0, color: Color(0x00000000))), ); } diff --git a/lib/thinking_indicator.dart b/lib/thinking_indicator.dart index 41a477d..7261bb6 100644 --- a/lib/thinking_indicator.dart +++ b/lib/thinking_indicator.dart @@ -17,9 +17,7 @@ class ThinkingIndicator extends ImplicitlyAnimatedWidget { this.height = 10.0, this.visible = true, super.key, - }) : super( - duration: Styling.thinkingFadeDuration, - ); + }) : super(duration: Styling.thinkingFadeDuration); @override ImplicitlyAnimatedWidgetState createState() => _ThinkingIndicatorState(); @@ -29,7 +27,6 @@ class _ThinkingIndicatorState extends AnimatedWidgetBaseState { Tween? _opacityTween; - @override Widget build(BuildContext context) { return Center( @@ -37,12 +34,10 @@ class _ThinkingIndicatorState height: widget.height, child: Opacity( opacity: _opacityTween!.evaluate(animation), - child: _opacityTween!.evaluate(animation) != 0 - ? AnimatedCircles( - color: widget.color, - height: widget.height, - ) - : null, + child: + _opacityTween!.evaluate(animation) != 0 + ? AnimatedCircles(color: widget.color, height: widget.height) + : null, ), ), ); @@ -50,11 +45,13 @@ class _ThinkingIndicatorState @override void forEachTween(visitor) { - _opacityTween = visitor( - _opacityTween, - widget.visible ? 1.0 : 0.0, - (dynamic value) => Tween(begin: value as double), - ) as Tween?; + _opacityTween = + visitor( + _opacityTween, + widget.visible ? 1.0 : 0.0, + (dynamic value) => Tween(begin: value as double), + ) + as Tween?; } } @@ -62,11 +59,7 @@ class AnimatedCircles extends StatefulWidget { final Color color; final double height; - const AnimatedCircles({ - required this.color, - required this.height, - super.key, - }); + const AnimatedCircles({required this.color, required this.height, super.key}); @override AnimatedCirclesState createState() => AnimatedCirclesState(); @@ -81,15 +74,17 @@ class AnimatedCirclesState extends State void initState() { super.initState(); _thinkingController = AnimationController( - duration: const Duration(milliseconds: 500), vsync: this) - ..addStatusListener((status) { - // This bit ensures that the animation reverses course rather than - // stopping. - if (status == AnimationStatus.completed) _thinkingController.reverse(); - if (status == AnimationStatus.dismissed) _thinkingController.forward(); - }); + duration: const Duration(milliseconds: 500), + vsync: this, + )..addStatusListener((status) { + // This bit ensures that the animation reverses course rather than + // stopping. + if (status == AnimationStatus.completed) _thinkingController.reverse(); + if (status == AnimationStatus.dismissed) _thinkingController.forward(); + }); _thinkingAnimation = Tween(begin: 0.0, end: widget.height).animate( - CurvedAnimation(parent: _thinkingController, curve: Curves.easeOut)); + CurvedAnimation(parent: _thinkingController, curve: Curves.easeOut), + ); _thinkingController.forward(); } @@ -104,10 +99,7 @@ class AnimatedCirclesState extends State width: widget.height, height: widget.height, decoration: BoxDecoration( - border: Border.all( - color: widget.color, - width: 2.0, - ), + border: Border.all(color: widget.color, width: 2.0), borderRadius: const BorderRadius.all(Radius.circular(5.0)), ), );