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

Amateur golden point #76

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions resources/menus/number_of_deuces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<menu id="DeucesMenu" title="Deuces">
<menu-item id="deuces_default" label="1st (default)" />
<menu-item id="deuces_amateur" label="2nd (amateur)" />
</menu>
10 changes: 8 additions & 2 deletions source/delegates/menu/menuGoldenPointDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ class MenuGoldenPointDelegate extends WatchUi.MenuInputDelegate {
}

Application.getApp().getMatchConfig().setGoldenPoint(goldenPoint);
WatchUi.pushView(new Rez.Menus.SetsMenu(), new MenuNumberSetsDelegate(), WatchUi.SLIDE_BLINK);

if (goldenPoint == false) {
WatchUi.pushView(new Rez.Menus.SetsMenu(), new MenuNumberSetsDelegate(), WatchUi.SLIDE_BLINK);
} else {
WatchUi.pushView(new Rez.Menus.DeucesMenu(), new MenuGoldenPointDeuceSettingsDelegate(), WatchUi.SLIDE_BLINK);
}

}

}
}
31 changes: 31 additions & 0 deletions source/delegates/menu/menuGoldenPointDeuceSettingsDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;

class MenuGoldenPointDeuceSettingsDelegate extends WatchUi.MenuInputDelegate {

function initialize() {
MenuInputDelegate.initialize();
}

function onMenuItem(item as Symbol) as Void {

var nbrDeuces = 1;

switch (item) {
case :deuces_default: {
nbrDeuces = 1;
break;
}
case :deuces_amateur: {
nbrDeuces = 2;
break;
}
}

Application.getApp().getMatchConfig().setNumberOfDeuces(nbrDeuces);
WatchUi.pushView(new Rez.Menus.SetsMenu(), new MenuNumberSetsDelegate(), WatchUi.SLIDE_BLINK);

}

}
78 changes: 70 additions & 8 deletions source/model/PadelMatch.mc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class PadelMatch {
private var numberOfSets;
private var superTie;
private var goldenPoint;
private var numberOfDeuces;

private var historicalScores;

Expand All @@ -17,6 +18,7 @@ class PadelMatch {
numberOfSets = config.getNumberOfSets();
superTie = config.getSuperTie();
goldenPoint = config.getGoldenPoint();
numberOfDeuces = config.getNumberOfDeuces();

matchStatus = MatchStatus.New();
prevMatchStatus = MatchStatus.New();
Expand Down Expand Up @@ -63,11 +65,41 @@ class PadelMatch {
// (mid game)

if (self.goldenPoint) {
// mid game
if (self.matchStatus.getP1Score() != 40) {
if (self.matchStatus.getP1Idx() > 3) { // winning phase
return incP1Game();
}

if (self.matchStatus.getP1Idx() < 3) { // less than 40
self.matchStatus.incP1Score();

if (self.matchStatus.getP1Score() == 40 && self.matchStatus.getP2Score() == 40) {
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
self.matchStatus.setGolden();
}
}
return false;
} else {
} else { // we are 40
if (self.matchStatus.getP2Idx() < 3) { // less than 40
return incP1Game();
}

if (self.matchStatus.getP2Idx() == 3) { // 40
self.matchStatus.incP1Score();
return false;
}

if (self.matchStatus.getP2Idx() > 3) { // Advantage
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
self.matchStatus.setGolden();
} else {
self.matchStatus.setDeuce();
}
return false;
}
return incP1Game();
}
} else {
Expand Down Expand Up @@ -143,11 +175,41 @@ class PadelMatch {
// (mid game)

if (self.goldenPoint) {
// mid game
if (self.matchStatus.getP2Score() != 40) {
if (self.matchStatus.getP2Idx() > 3) { // winning phase
return incP2Game();
}

if (self.matchStatus.getP2Idx() < 3) { // less than 40
self.matchStatus.incP2Score();

if (self.matchStatus.getP2Score() == 40 && self.matchStatus.getP1Score() == 40) {
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
self.matchStatus.setGolden();
}
}
return false;
} else {
} else { // we are 40
if (self.matchStatus.getP1Idx() < 3) { // less than 40
return incP2Game();
}

if (self.matchStatus.getP1Idx() == 3) { // 40
self.matchStatus.incP2Score();
return false;
}

if (self.matchStatus.getP1Idx() > 3) { // Advantage
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
self.matchStatus.setGolden();
} else {
self.matchStatus.setDeuce();
}
return false;
}
return incP2Game();
}
} else {
Expand Down Expand Up @@ -221,7 +283,7 @@ class PadelMatch {
totalPlayedSets == self.numberOfSets ||
abs(self.matchStatus.getP1Sets() - self.matchStatus.getP2Sets()) > self.numberOfSets - totalPlayedSets;

}
}

function finishSuperTie() as Boolean {
var result = "" + self.matchStatus.getP1TieScore() + "-" + self.matchStatus.getP2TieScore();
Expand All @@ -245,4 +307,4 @@ class PadelMatch {
function resetAfterGameFinish() {
self.matchStatus.resetScores();
}
}
}
16 changes: 13 additions & 3 deletions source/model/matchConfig.mc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class MatchConfig {
private var superTie;
private var numberOfSets;
private var goldenPoint;
private var numberOfDeuces;

function initialize() {
superTie = false;
numberOfSets = UNLIMITED_SETS;
goldenPoint = true;
goldenPoint = true;
numberOfDeuces = 1;
}

function setGoldenPoint(goldenPoint as Boolean) as Void {
Expand All @@ -34,12 +36,20 @@ class MatchConfig {
self.numberOfSets = sets;
}

function setNumberOfDeuces(deuces as Number) as Void {
self.numberOfDeuces = deuces;
}

function getNumberOfDeuces() as Number {
return self.numberOfDeuces;
}

function getNumberOfSets() as Number {
return self.numberOfSets;
}

function toString() as Lang.String {
return "matchConfig: " + "superTie: " + self.superTie + ", sets: " + self.numberOfSets + ", golden: " + self.goldenPoint;
return "matchConfig: " + "superTie: " + self.superTie + ", sets: " + self.numberOfSets + ", golden: " + self.goldenPoint + ", deuces: " + self.numberOfDeuces;
}

}
}
37 changes: 32 additions & 5 deletions source/model/matchStatus.mc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MatchStatus {

static const AVAILABLE_POINTS = [0, 15, 30, 40, 'A'];
static const AVAILABLE_POINTS = [0, 15, 30, 40, 'A', 'G'];

private var p1Sets;
private var p2Sets;
Expand All @@ -14,11 +14,13 @@ class MatchStatus {
private var p1TieBreakScore;
private var p2TieBreakScore;

private var totalDeuces;

static function New() {
return new MatchStatus(0,0,0,0,0,0,0,0);
return new MatchStatus(0,0,0,0,0,0,0,0,0);
}

function initialize(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore) {
function initialize(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore, totalDeuces) {
self.p1Sets = p1Sets;
self.p2Sets = p2Sets;

Expand All @@ -30,6 +32,8 @@ class MatchStatus {

self.p1TieBreakScore = p1TieBreakScore;
self.p2TieBreakScore = p2TieBreakScore;

self.totalDeuces = totalDeuces;
}


Expand Down Expand Up @@ -57,6 +61,10 @@ class MatchStatus {
self.p1ScoreIdx++;
}

function getP1Idx() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is somehow new. the p1Idx and p2Idx were not exposed on purpose. it's an internal data structure that should not be used by anyone else other than the matchStatus class. callers should look into the score only

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this change happened because we want to display the G-G score when in golden point right? i feel we should revert it. instead of doing this, can we infer we are in the G-G state by looking at the score and at the number of deuces?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is somehow new. the p1Idx and p2Idx were not exposed on purpose. it's an internal data structure that should not be used by anyone else other than the matchStatus class. callers should look into the score only

How come not here? That's the file where I found all the functions, it seemed more practical to draw from here since you have an index with all the scores.
So if I understand you correctly, you would rather create a second function that does the calculations and just returns the value? How were you planning to proceed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this change happened because we want to display the G-G score when in golden point right? i feel we should revert it. instead of doing this, can we infer we are in the G-G state by looking at the score and at the number of deuces?

Trying this feature, I realized that a visual indication is better, because it happens that the point lasts a very long time, so long that you don't remember accurately the score, which is then one of the purposes of the application. I think it's happened to you playing as well, points of a long duration that at the conclusion you don't know the score. So the ploy, you run out of deuces available, the application points to G-G which reminds you that you are at the Golden Point and the point is decisive. The same thing happens with A if you think about it.
I would take advantage of the dedicated array of scores and "play" by moving the index time by time.
How would you do that?

return self.p1ScoreIdx;
}

function getP1TieScore() {
return self.p1TieBreakScore;
}
Expand Down Expand Up @@ -89,6 +97,10 @@ class MatchStatus {
self.p2ScoreIdx++;
}

function getP2Idx() {
return self.p2ScoreIdx;
}

function getP2TieScore() {
return self.p2TieBreakScore;
}
Expand All @@ -97,11 +109,24 @@ class MatchStatus {
self.p2TieBreakScore++;
}

function getTotalOfDeuces() {
return self.totalDeuces;
}

function incTotalOfDeuces() {
self.totalDeuces++;
}

function setDeuce() {
self.p1ScoreIdx = 3;
self.p2ScoreIdx = 3;
}

function setGolden() {
self.p1ScoreIdx = 5;
self.p2ScoreIdx = 5;
}

function resetGames() {
self.p1Games = 0;
self.p2Games = 0;
Expand All @@ -113,9 +138,11 @@ class MatchStatus {

self.p2ScoreIdx = 0;
self.p2TieBreakScore = 0;

self.totalDeuces = 0;
}

function copy() as MatchStatus {
return new MatchStatus(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore);
return new MatchStatus(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore, totalDeuces);
}
}
}
Loading