Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play versus computer #1310

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/src/model/challenge/challenge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract mixin class BaseChallenge {
bool get rated;
SideChoice get sideChoice;
String? get initialFen;
int? get aiLevel;


TimeIncrement? get timeIncrement =>
clock != null ? TimeIncrement(clock!.time.inSeconds, clock!.increment.inSeconds) : null;
Expand Down Expand Up @@ -53,6 +55,7 @@ class Challenge with _$Challenge, BaseChallenge implements BaseChallenge {
ChallengeUser? destUser,
ChallengeDeclineReason? declineReason,
String? initialFen,
int? aiLevel,
ChallengeDirection? direction,
}) = _Challenge;

Expand Down Expand Up @@ -123,6 +126,7 @@ class ChallengeRequest with _$ChallengeRequest, BaseChallenge implements BaseCha
required bool rated,
required SideChoice sideChoice,
String? initialFen,
int? aiLevel,
}) = _ChallengeRequest;

@override
Expand All @@ -142,6 +146,7 @@ class ChallengeRequest with _$ChallengeRequest, BaseChallenge implements BaseCha
'variant': variant.name,
if (variant == Variant.fromPosition) 'fen': initialFen,
if (sideChoice != SideChoice.random) 'color': sideChoice.name,
if (destUser.id == const UserId('ai')) 'level': aiLevel.toString(),
};
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/model/challenge/challenge_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class ChallengePreferences extends _$ChallengePreferences
Future<void> setRated(bool rated) {
return save(state.copyWith(rated: rated));
}

Future<void> setLevel(int aiLevel) {
return save(state.copyWith(aiLevel: aiLevel));
}
}

@Freezed(fromJson: true, toJson: true)
Expand All @@ -65,6 +69,7 @@ class ChallengePrefs with _$ChallengePrefs implements Serializable {
required int days,
required bool rated,
required SideChoice sideChoice,
required int aiLevel,
}) = _ChallengePrefs;

static const defaults = ChallengePrefs(
Expand All @@ -74,6 +79,7 @@ class ChallengePrefs with _$ChallengePrefs implements Serializable {
days: 3,
rated: false,
sideChoice: SideChoice.random,
aiLevel: 1,
);

Speed get speed =>
Expand All @@ -90,6 +96,7 @@ class ChallengePrefs with _$ChallengePrefs implements Serializable {
days: timeControl == ChallengeTimeControlType.correspondence ? days : null,
rated: rated,
sideChoice: sideChoice,
aiLevel: aiLevel,
initialFen: initialFen,
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/model/challenge/challenge_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ChallengeRepository {
}

Future<Challenge> create(ChallengeRequest challenge) async {
final uri = Uri(path: '/api/challenge/${challenge.destUser.id}');
final userId = challenge.destUser.id;
final uri = Uri(path: '/api/challenge/$userId');
return client.postReadJson(
uri,
body: challenge.toRequestBody,
Expand Down
Loading
Loading