Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • SuborbitalPigeon/rugby
  • webpigeon/rugby
2 results
Show changes
#ifndef __RUGBY_SCORE_STORE_H__
#define __RUGBY_SCORE_STORE_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
enum
{
RUGBY_SCORE_STORE_TRIES,
RUGBY_SCORE_STORE_UTRIES,
RUGBY_SCORE_STORE_KICKS,
RUGBY_SCORE_STORE_TOOLTIP,
RUGBY_SCORE_STORE_COLUMNS
};
#define RUGBY_TYPE_SCORE_STORE rugby_score_store_get_type ()
G_DECLARE_FINAL_TYPE (RugbyScoreStore, rugby_score_store, RUGBY, SCORE_STORE, GtkListStore)
RugbyScoreStore * rugby_score_store_new (void);
gint rugby_score_store_get_score (RugbyScoreStore *store);
void rugby_score_store_set_score (RugbyScoreStore *store,
gint score);
G_END_DECLS
#endif /* __RUGBY_SCORE_STORE_H__ */
#include "rugby-scoring.h"
/**
* rugby_scoring_get_possibilities:
* @score: the score of a team
*
* Gets the possible ways of scoring @score points, as a %GVariant of the
* type "a(iii)", in the order "tries, utries, pens".
*
* Returns: (transfer-none): the possibilities, or %NULL in the case there are
* none
*/
GVariant *
rugby_scoring_get_possibilities (gint score)
{
GVariantBuilder builder;
gint possibilities = 0;
gint max_tries, max_utries;
gint tries, utries;
g_return_val_if_fail (score >= 0, NULL);
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
max_tries = (gint) (score / TRY_POINTS);
max_utries = (gint) (score / UTRY_POINTS);
for (tries = 0; tries <= max_tries; tries++)
{
for (utries = 0; utries <= max_utries; utries++)
{
gint left;
/* Calculate left over score for penalties */
left = score - (tries * TRY_POINTS) - (utries * UTRY_POINTS);
if (left < 0)
continue;
/* If the score after pens is 0, it's a possibility */
if (left % KICK_POINTS == 0)
{
gint pens;
pens = left / KICK_POINTS;
/* Add result to variant */
g_variant_builder_add (&builder, "(iii)", tries, utries, pens);
possibilities++;
}
}
}
if (possibilities == 0)
return NULL;
else
return g_variant_builder_end (&builder);
}
/**
* rugby_scoring_get_max_tries:
* @score: the score of a team
*
* Gets the maximum number of tries possible for a given score. Not related to
* Max Evans.
*
* Returns: the maximum number of tries possible
*/
gint
rugby_scoring_get_max_tries (gint score)
{
return (score % 5 == 1) ? score / UTRY_POINTS - 1 : score / UTRY_POINTS;
}
/**
* rugby_scoring_get_max_kicks:
* @score: the score of a team
*
* Gets the maximum number of kicks (penalties and drop goals) for a given score.
*
* Returns: the maximum number of kicks possible
*/
gint
rugby_scoring_get_max_kicks (gint score)
{
return (score % 3 == 1) ? score / KICK_POINTS : score / KICK_POINTS - 1;
}
#ifndef __RUGBY_SCORING_H__
#define __RUGBY_SCORING_H__
#include <glib.h>
G_BEGIN_DECLS
#define TRY_POINTS 7
#define UTRY_POINTS 5
#define KICK_POINTS 3
typedef enum
{
RUGBY_SCORE_TYPE_TRY,
RUGBY_SCORE_TYPE_UTRY,
RUGBY_SCORE_TYPE_KICK
} RugbyScoreType;
GVariant * rugby_scoring_get_possibilities (gint score);
gint rugby_scoring_get_max_tries (gint score);
gint rugby_scoring_get_max_kicks (gint score);
G_END_DECLS
#endif /*__RUGBY_SCORING_H__ */
#include "rugby-application.h"
int
main (int argc,
char **argv)
{
RugbyApplication *app;
gint retval;
app = rugby_application_new ();
retval = g_application_run (G_APPLICATION (app), argc, argv);
return retval;
}
# SPDX-FileCopyrightText: 2022-2024 Bruce Cowan
#
# SPDX-License-Identifier: CC0-1.0
[wrap-git]
directory = blueprint-compiler
url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git
revision = v0.14.0
depth = 1
[provide]
program_names = blueprint-compiler
{
"app-id": "uk.me.bcowan.Rugby",
"runtime": "org.gnome.Platform",
"runtime-version": "47",
"sdk": "org.gnome.Sdk",
"command": "rugby",
"finish-args": [
"--share=ipc",
"--device=dri",
"--socket=fallback-x11",
"--socket=wayland"
],
"modules": [
{
"name": "blueprint-compiler",
"buildsystem": "meson",
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
"tag": "v0.14.0"
}
]
},
{
"name": "rugby",
"buildsystem": "meson",
"builddir": true,
"sources": [
{
"type": "dir",
"path": "."
}
],
"config-opts": [
"-Dprofile=development"
]
}
]
}
SPDX-FileCopyrightText: 2024 Bruce Cowan <bruce@bcowan.me.uk>
SPDX-License-Identifier: GPL-3.0-or-later