/* rugby-scoring.c * * Copyright © 2012, 2017 Bruce Cowan <bruce@bcowan.eu> * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "rugby-possibility.h" #include "rugby-scoring.h" void rugby_scoring_get_possibilities (GListStore *store, gint score) { gint max_tries = score / TRY_POINTS; gint max_utries = score / UTRY_POINTS; g_list_store_remove_all (store); for (gint tries = 0; tries <= max_tries; tries++) { for (gint utries = 0; utries <= max_utries; utries++) { gint left = score - (tries * TRY_POINTS) - (utries * UTRY_POINTS); if (left < 0) continue; if (left % KICK_POINTS == 0) { gint kicks = left / KICK_POINTS; g_autoptr(RugbyPossibility) possibility = rugby_possibility_new (tries, utries, kicks); g_list_store_append (store, possibility); } } } } gint rugby_scoring_get_max_tries (gint score) { return (score % 5 == 1) ? score / UTRY_POINTS - 1 : score / UTRY_POINTS; } gint rugby_scoring_get_max_kicks (gint score) { return (score % 3 == 1) ? score / KICK_POINTS : score / KICK_POINTS - 1; }