Skip to content

Commit af1c091

Browse files
committed
Updated formatting. Thanks 3.7
1 parent e1b1a6d commit af1c091

File tree

6 files changed

+97
-124
lines changed

6 files changed

+97
-124
lines changed

lib/game_board.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GameBoard {
4040

4141
/// Copy constructor.
4242
GameBoard.fromGameBoard(GameBoard other)
43-
: rows = List.generate(height, (i) => List.from(other.rows[i]));
43+
: rows = List.generate(height, (i) => List.from(other.rows[i]));
4444

4545
/// Retrieves the type of piece at a location on the game board.
4646
PieceType getPieceAtLocation(int x, int y) {
@@ -51,10 +51,7 @@ class GameBoard {
5151

5252
/// Gets the total number of pieces of a particular type.
5353
int getPieceCount(PieceType pieceType) {
54-
return rows.fold(
55-
0,
56-
(s, e) => s + e.where((e) => e == pieceType).length,
57-
);
54+
return rows.fold(0, (s, e) => s + e.where((e) => e == pieceType).length);
5855
}
5956

6057
/// Calculates the list of available moves on this board for a player. These
@@ -136,7 +133,13 @@ class GameBoard {
136133
// to true, the pieces are flipped in place to their new colors before the
137134
// method returns.
138135
bool _traversePath(
139-
int x, int y, int dx, int dy, PieceType player, bool flip) {
136+
int x,
137+
int y,
138+
int dx,
139+
int dy,
140+
PieceType player,
141+
bool flip,
142+
) {
140143
var foundOpponent = false;
141144
var curX = x + dx;
142145
var curY = y + dy;

lib/game_model.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ class GameModel {
1010
late final GameBoard board;
1111
final PieceType player;
1212

13-
GameModel({
14-
required this.board,
15-
this.player = PieceType.black,
16-
});
13+
GameModel({required this.board, this.player = PieceType.black});
1714

1815
int get blackScore => board.getPieceCount(PieceType.black);
1916

lib/main.dart

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class FlutterFlipApp extends StatelessWidget {
4040
onGenerateRoute: (settings) {
4141
return PageRouteBuilder<dynamic>(
4242
settings: settings,
43-
pageBuilder: (context, animation, secondaryAnimation) =>
44-
const GameScreen(),
43+
pageBuilder:
44+
(context, animation, secondaryAnimation) => const GameScreen(),
4545
);
4646
},
4747
);
@@ -145,14 +145,16 @@ class GameScreenState extends State<GameScreen> {
145145

146146
Widget _buildScoreBox(PieceType player, GameModel model) {
147147
var label = player == PieceType.black ? 'black' : 'white';
148-
var scoreText = player == PieceType.black
149-
? '${model.blackScore}'
150-
: '${model.whiteScore}';
148+
var scoreText =
149+
player == PieceType.black
150+
? '${model.blackScore}'
151+
: '${model.whiteScore}';
151152

152153
return DecoratedBox(
153-
decoration: (model.player == player)
154-
? Styling.activePlayerIndicator
155-
: Styling.inactivePlayerIndicator,
154+
decoration:
155+
(model.player == player)
156+
? Styling.activePlayerIndicator
157+
: Styling.inactivePlayerIndicator,
156158
child: Column(
157159
children: <Widget>[
158160
Text(
@@ -164,7 +166,7 @@ class GameScreenState extends State<GameScreen> {
164166
scoreText,
165167
textAlign: TextAlign.center,
166168
style: Styling.scoreText,
167-
)
169+
),
168170
],
169171
),
170172
);
@@ -177,32 +179,34 @@ class GameScreenState extends State<GameScreen> {
177179
final spots = <Widget>[];
178180

179181
for (var x = 0; x < GameBoard.width; x++) {
180-
spots.add(AnimatedContainer(
181-
duration: const Duration(
182-
milliseconds: 500,
183-
),
184-
margin: const EdgeInsets.all(1.0),
185-
decoration: BoxDecoration(
186-
gradient:
187-
Styling.pieceGradients[model.board.getPieceAtLocation(x, y)],
188-
),
189-
child: SizedBox(
190-
width: 40.0,
191-
height: 40.0,
192-
child: GestureDetector(
193-
onTap: () {
194-
_attemptUserMove(model, x, y);
195-
},
182+
spots.add(
183+
AnimatedContainer(
184+
duration: const Duration(milliseconds: 500),
185+
margin: const EdgeInsets.all(1.0),
186+
decoration: BoxDecoration(
187+
gradient:
188+
Styling.pieceGradients[model.board.getPieceAtLocation(x, y)],
189+
),
190+
child: SizedBox(
191+
width: 40.0,
192+
height: 40.0,
193+
child: GestureDetector(
194+
onTap: () {
195+
_attemptUserMove(model, x, y);
196+
},
197+
),
196198
),
197199
),
198-
));
200+
);
199201
}
200202

201-
rows.add(Row(
202-
mainAxisSize: MainAxisSize.min,
203-
mainAxisAlignment: MainAxisAlignment.center,
204-
children: spots,
205-
));
203+
rows.add(
204+
Row(
205+
mainAxisSize: MainAxisSize.min,
206+
mainAxisAlignment: MainAxisAlignment.center,
207+
children: spots,
208+
),
209+
);
206210
}
207211

208212
return rows;
@@ -214,16 +218,11 @@ class GameScreenState extends State<GameScreen> {
214218
child: Column(
215219
mainAxisSize: MainAxisSize.min,
216220
children: [
217-
Text(
218-
model.gameResultString,
219-
style: Styling.resultText,
220-
),
221+
Text(model.gameResultString, style: Styling.resultText),
221222
const SizedBox(height: 30),
222223
GestureDetector(
223224
onTap: () {
224-
_restartController.add(
225-
GameModel(board: GameBoard()),
226-
);
225+
_restartController.add(GameModel(board: GameBoard()));
227226
},
228227
child: Container(
229228
decoration: BoxDecoration(
@@ -232,10 +231,7 @@ class GameScreenState extends State<GameScreen> {
232231
),
233232
child: const Padding(
234233
padding: EdgeInsets.fromLTRB(15, 5, 15, 9),
235-
child: Text(
236-
'new game',
237-
style: Styling.buttonText,
238-
),
234+
child: Text('new game', style: Styling.buttonText),
239235
),
240236
),
241237
),
@@ -252,10 +248,7 @@ class GameScreenState extends State<GameScreen> {
252248
gradient: LinearGradient(
253249
begin: Alignment.topLeft,
254250
end: Alignment.bottomRight,
255-
colors: [
256-
Styling.backgroundStartColor,
257-
Styling.backgroundFinishColor,
258-
],
251+
colors: [Styling.backgroundStartColor, Styling.backgroundFinishColor],
259252
),
260253
),
261254
child: SafeArea(

lib/move_finder.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class ScoredMove {
3333
// This is that method for [MoveFinder].
3434
Position? _findNextMove(MoveSearchArgs args) {
3535
final bestMove = _performSearchPly(
36-
args.board, args.player, args.player, args.numPlies - 1);
36+
args.board,
37+
args.player,
38+
args.player,
39+
args.numPlies - 1,
40+
);
3741
return bestMove?.move;
3842
}
3943

@@ -55,12 +59,16 @@ ScoredMove? _performSearchPly(
5559
ScoredMove? bestMove;
5660

5761
for (var i = 0; i < availableMoves.length; i++) {
58-
final newBoard =
59-
board.updateForMove(availableMoves[i].x, availableMoves[i].y, player);
62+
final newBoard = board.updateForMove(
63+
availableMoves[i].x,
64+
availableMoves[i].y,
65+
player,
66+
);
6067
if (pliesRemaining > 0 &&
6168
newBoard.getMovesForPlayer(player.opponent).isNotEmpty) {
6269
// Opponent has next turn.
63-
score = _performSearchPly(
70+
score =
71+
_performSearchPly(
6472
newBoard,
6573
scoringPlayer,
6674
player.opponent,
@@ -70,7 +78,8 @@ ScoredMove? _performSearchPly(
7078
} else if (pliesRemaining > 0 &&
7179
newBoard.getMovesForPlayer(player).isNotEmpty) {
7280
// Opponent has no moves; player gets another turn.
73-
score = _performSearchPly(
81+
score =
82+
_performSearchPly(
7483
newBoard,
7584
scoringPlayer,
7685
player,
@@ -85,8 +94,10 @@ ScoredMove? _performSearchPly(
8594
if (bestMove == null ||
8695
(score > bestMove.score && scoringPlayer == player) ||
8796
(score < bestMove.score && scoringPlayer != player)) {
88-
bestMove =
89-
ScoredMove(score, Position(availableMoves[i].x, availableMoves[i].y));
97+
bestMove = ScoredMove(
98+
score,
99+
Position(availableMoves[i].x, availableMoves[i].y),
100+
);
90101
}
91102
}
92103

@@ -107,11 +118,7 @@ class MoveFinder {
107118
Future<Position?> findNextMove(PieceType player, int numPlies) {
108119
return compute(
109120
_findNextMove,
110-
MoveSearchArgs(
111-
board: initialBoard,
112-
player: player,
113-
numPlies: numPlies,
114-
),
121+
MoveSearchArgs(board: initialBoard, player: player, numPlies: numPlies),
115122
);
116123
}
117124
}

lib/styling.dart

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,17 @@ abstract class Styling {
1919
PieceType.black: LinearGradient(
2020
begin: Alignment.topLeft,
2121
end: Alignment.bottomRight,
22-
colors: [
23-
Color(0xff101010),
24-
Color(0xff303030),
25-
],
22+
colors: [Color(0xff101010), Color(0xff303030)],
2623
),
2724
PieceType.white: LinearGradient(
2825
begin: Alignment.topLeft,
2926
end: Alignment.bottomRight,
30-
colors: [
31-
Color(0xffffffff),
32-
Color(0xffe0e0e0),
33-
],
27+
colors: [Color(0xffffffff), Color(0xffe0e0e0)],
3428
),
3529
PieceType.empty: LinearGradient(
3630
begin: Alignment.topLeft,
3731
end: Alignment.bottomRight,
38-
colors: [
39-
Color(0x60ffffff),
40-
Color(0x40ffffff),
41-
],
32+
colors: [Color(0x60ffffff), Color(0x40ffffff)],
4233
),
4334
};
4435

@@ -89,20 +80,10 @@ abstract class Styling {
8980
// **** BOXES ****
9081

9182
static const activePlayerIndicator = BoxDecoration(
92-
border: Border(
93-
bottom: BorderSide(
94-
width: 2.0,
95-
color: Color(0xffffffff),
96-
),
97-
),
83+
border: Border(bottom: BorderSide(width: 2.0, color: Color(0xffffffff))),
9884
);
9985

10086
static const inactivePlayerIndicator = BoxDecoration(
101-
border: Border(
102-
bottom: BorderSide(
103-
width: 2.0,
104-
color: Color(0x00000000),
105-
),
106-
),
87+
border: Border(bottom: BorderSide(width: 2.0, color: Color(0x00000000))),
10788
);
10889
}

0 commit comments

Comments
 (0)