Compare commits

..

10 commits

Author SHA1 Message Date
greek
b5db91addb Optimised suboptimal code. 2024-06-09 13:25:58 +01:00
greek
810ca0d9f5 Do no allow resizing of window.
Some small documenting.
Removed old street bets files.
2024-06-08 17:35:27 +01:00
greek
982212806f Column bitmaps were swapped; unswapped them. 2024-06-08 13:04:26 +01:00
greek
b93630dff5 Only allow croupier to choose single numbers. 2024-06-08 13:02:32 +01:00
greek
fd7a8fbd8a Payout button disabled until croupier has been set
Fixed potential segfault on startup if focusedPlayer_ is out of bounds.
2024-06-08 12:55:29 +01:00
greek
256d3740f9 Forgot to stage Results.qml file.
Also added thousands separators to numebrs where appropriate.
2024-06-08 12:27:23 +01:00
greek
6e770239c8 Only allow valid inputs as bets. 2024-06-08 12:25:20 +01:00
greek
4b19c90450 Display payout results.
Also fixed problem with some numbers not having enough bits.
Fixed indexes on single bets being different from what was expected.
2024-06-08 10:58:34 +01:00
greek
ffcc5f892c Calculate payouts. 2024-06-08 00:41:25 +01:00
greek
f72c5b781f Payout button stub. 2024-06-07 18:03:22 +01:00
12 changed files with 251 additions and 80 deletions

View file

@ -20,10 +20,15 @@ Item {
border.width: 0
color: {
if (PlayerAreaModel.focusedPlayer == 0 && rouletteTable.numberOfBets == 1 && border.width != 3) {
"#00000000"
} else if (rouletteTable.numberOfBets < 2 || border.width == 3) {
if ((PlayerAreaModel.focusedPlayer == 0 && rouletteTable.numberOfBets < 1) || PlayerAreaModel.focusedPlayer != 0 || border.width == 3) {
/*
* A bit of a mess
* The left side of the OR is checking if the player is croupier, and if it is, if it hasn't made a bet that has to be a number.
* Even if the above isn't true, it still highlights if it's hovering a bet so that it can remove the bet.
*
* The right side of the OR is similar logic but for normal players that can make two bets on any square of the board
*/
if (((PlayerAreaModel.focusedPlayer == 0 && betType == 9) && (rouletteTable.numberOfBets < 1 || border.width == 3)) ||
(PlayerAreaModel.focusedPlayer != 0 && (rouletteTable.numberOfBets < 2 || border.width == 3))) {
if (tapHandler.pressed) {
"#88999999"
} else if (hoverHandler.hovered) {
@ -34,9 +39,6 @@ Item {
} else {
"#00000000"
}
} else {
"#00000000"
}
}
HoverHandler {
@ -46,9 +48,12 @@ Item {
id: tapHandler
onTapped: {
if (PlayerAreaModel.focusedPlayer == 0 && rouletteTable.numberOfBets == 1 && parent.border.width != 3) {
} else if (rouletteTable.numberOfBets < 2 && parent.border.width == 0) {
/*
* Similar logic to what is used for setting the color attribute, but this time only go inside the "if" if a bet hasn't
* been made on the square that was clicked.
*/
if (((PlayerAreaModel.focusedPlayer == 0 && betType == 9) && (rouletteTable.numberOfBets < 1 && parent.border.width != 3)) ||
(PlayerAreaModel.focusedPlayer != 0 && (rouletteTable.numberOfBets < 2 && parent.border.width != 3))) {
parent.border.width = 3
/* Don't show this dialog for the croupier */

View file

@ -17,6 +17,8 @@ Dialog {
TextField {
id: input
focus: true
/* No negative numners or leading 0s, and cap at 99 million */
validator: RegularExpressionValidator { regularExpression: /[1-9][0-9]{0,7}/ }
anchors {
left: parent.left

View file

@ -45,7 +45,7 @@ qt_add_qml_module(roulette-payout
RedBlack.qml
EvenOdd.qml
LowHigh.qml
Results.qml
)
target_link_libraries(roulette-payout PRIVATE

View file

@ -11,7 +11,7 @@ MainWindow::MainWindow(QWindow *parent)
{
/*
* MainWindow is a QQmlApplicationEngine, so a .show() isn't needed
* it will load a Window or ApplicationWindow that will set its own
* It will load a Window or ApplicationWindow that will set its own
* visibility status
*/
load(QUrl("qrc:///Root.qml"));

View file

@ -1,12 +1,19 @@
#include "PlayerAreaModel.h"
#include <cstdint>
PlayerAreaModel::PlayerAreaModel(QObject *parent)
{
Player defaultValues;
Bet defaultBets;
for(int i = 0; i < 8; i++){
players.append(defaultValues);
for (int ii = 0; ii < 2; ii++) {
players[i].bets.append(defaultBets);
}
}
/* This is set to avoid segfaults if the starting value is out of bounds */
focusedPlayer_ = 1;
}
uint PlayerAreaModel::focusedPlayer()
@ -18,10 +25,10 @@ void PlayerAreaModel::setFocusedPlayer(int n)
{
focusedPlayer_ = n;
Player player = players.at(n);
BetType b1 = player.bet1.betType;
BetType b2 = player.bet2.betType;
uint n1 = player.bet1.betSpot;
uint n2 = player.bet2.betSpot;
BetType b1 = player.bets[0].betType;
BetType b2 = player.bets[1].betType;
uint n1 = player.bets[0].betSpot;
uint n2 = player.bets[1].betSpot;
emit focusedPlayerChanged(b1, n1, b2, n2);
}
@ -32,51 +39,111 @@ QString PlayerAreaModel::getPlayerName(int n)
void PlayerAreaModel::setPlayerName(QString s, int n)
{
this->players[n].playerName = s;
players[n].playerName = s;
}
void PlayerAreaModel::bet(BetType b, int n, int bet)
{
Player *player = &players[focusedPlayer_];
if (player->bet1.betType == NONE) {
player->bet1.betType = b;
player->bet1.betValue = bet;
player->bet1.betSpot = n;
if (b == 9 && n <= 35) {
for (int i = 0; i < 2; i++) {
if (player->bets[i].betType == NONE) {
player->bets[i].betType = b;
player->bets[i].betValue = bet;
player->bets[i].betSpot = n;
/*
* This is needed because the visual roulette board is inverted from the
* actual QML grid we use to represent it.
* Here we use 35 because the grid is 0-indexed, but later we use 36 when it is 1-indexed.
*/
if (b == SINGLE && n <= 35) {
n = 35 - n;
}
emit betChanged(b, n, bet);
} else if (player->bet2.betType == NONE) {
player->bet2.betType = b;
player->bet2.betValue = bet;
player->bet2.betSpot = n;
if (b == 9 && n <= 35) {
n = 35 - n;
break;
}
emit betChanged(b, n, bet);
}
}
void PlayerAreaModel::removeBet(BetType b, int n)
{
Player *player = &players[focusedPlayer_];
if (player->bet1.betType != NONE) {
player->bet1.betType = NONE;
if (b == 9 && n <= 35) {
for (int i = 0; i < 2; i++) {
if (player->bets[i].betType == b && player->bets[i].betSpot == n) {
player->bets[i].betType = NONE;
if (b == SINGLE && n <= 35) {
n = 35 - n;
}
emit betRemoved(b, n);
} else {
player->bet2.betType = NONE;
if (b == 9 && n <= 35) {
n = 35 - n;
}
emit betRemoved(b, n);
}
}
void PlayerAreaModel::cancelBet(BetType b, int n) {
void PlayerAreaModel::cancelBet(BetType b, int n)
{
emit betCanceled(b, n);
}
void PlayerAreaModel::payout()
{
if (players.at(0).bets[0].betType == NONE) {
fprintf(stderr, "Select where the ball landed\n");
} else {
int rollSpot = 36 - players.at(0).bets[0].betSpot;
for (int i = 1; i < 8; i++) {
players[i].payout = 0;
for (int ii = 0; ii < 2; ii++) {
int betType = players.at(i).bets[ii].betType;
int betSpot;
if (betType != NONE) {
betSpot = players.at(i).bets[ii].betSpot;
if (betType == SINGLE && betSpot <= 35) {
betSpot = 36 - betSpot;
} else {
betSpot += 1;
}
if (betType == SINGLE && betSpot == rollSpot) {
players[i].payout += players.at(i).bets[ii].betValue * 21;
} else if (betType == RED && (((int64_t)1 << (rollSpot - 1)) & redNumbers)) {
players[i].payout += players.at(i).bets[ii].betValue * 2;
} else if (betType == BLACK && !(((int64_t)1 << (rollSpot - 1)) & redNumbers)) {
players[i].payout += players.at(i).bets[ii].betValue * 2;
} else if (betType == ODD && (rollSpot % 2)) {
players[i].payout += players.at(i).bets[ii].betValue * 2;
} else if (betType == EVEN && !(rollSpot % 2)) {
players[i].payout += players.at(i).bets[ii].betValue * 2;
} else if (betType == LOW && rollSpot <= 18 ) {
players[i].payout += players.at(i).bets[ii].betValue * 2;
} else if (betType == HIGH && rollSpot >= 19 && rollSpot < 37) {
players[i].payout += players.at(i).bets[ii].betValue * 2;
} else if (betType == DOZEN) {
printf("CHECK %d %d\n", betSpot, rollSpot);
if (rollSpot <= 12 * betSpot && rollSpot >= (12 * (betSpot - 1)) + 1) {
players[i].payout += players.at(i).bets[ii].betValue * 3;
}
} else if (betType == STREET) {
if (rollSpot <= 3 * betSpot && rollSpot >= (3 * (betSpot - 1)) + 1) {
players[i].payout += players.at(i).bets[ii].betValue * 6;
}
} else if (betType == COLUMN) {
if (betSpot == 1 && (((int64_t)1 << (rollSpot - 1)) & column1)) {
players[i].payout += players.at(i).bets[ii].betValue * 3;
} else if (betSpot == 2 && (((int64_t)1 << (rollSpot - 1)) & column2)) {
players[i].payout += players.at(i).bets[ii].betValue * 3;
} else if (betSpot == 3 && (((int64_t)1 << (rollSpot - 1)) & column3)) {
players[i].payout += players.at(i).bets[ii].betValue * 3;
}
}
}
}
emit results(players.at(i).playerName, i, players.at(i).payout);
}
}
}

View file

@ -2,6 +2,7 @@
#include <QQuickView>
#include <QtGui/qwindow.h>
#include <cstdint>
#include <qobject.h>
#include <qqmlintegration.h>
#include <qtmetamacros.h>
@ -10,6 +11,7 @@
class PlayerAreaModel : public QObject
{
Q_OBJECT
/* The name under which this "global variable" will be known in QML files */
QML_NAMED_ELEMENT(PlayerAreaModel)
QML_SINGLETON
@ -42,6 +44,7 @@ signals:
void betChanged(BetType b, int n, int bet);
void betRemoved(BetType b, int n);
void betCanceled(BetType b, uint n);
void results(QString name, int n, int payout);
public slots:
void setPlayerName(QString s, int n);
@ -49,10 +52,10 @@ public slots:
void removeBet(BetType b, int n);
QString getPlayerName(int n);
void cancelBet(BetType b, int n);
void payout();
private:
struct Bet {
uint betValue = 0;
BetType betType = NONE;
@ -61,11 +64,17 @@ private:
struct Player {
QString playerName = "";
Bet bet1;
Bet bet2;
QList<Bet> bets;
int payout;
};
QList<Player> players;
int focusedPlayer_;
/* bitmaps */
int64_t redNumbers = 45857548629;
int64_t column3 = 9817068105;
int64_t column2 = 19634136210;
int64_t column1 = 39268272420;
};

View file

@ -129,7 +129,7 @@ Item {
topMargin: 6
}
onTextEdited: PlayerAreaModel.setPlayerName(text, index)
onTextEdited: PlayerAreaModel.setPlayerName(text, index + 1)
onActiveFocusChanged: {
/* focusReason 0, 1 and 2 are mouse, tab forward, and tab backward, respectively */
if (activeFocus && (focusReason == 0 || focusReason == 1 || focusReason == 2)) {
@ -179,17 +179,17 @@ Item {
currentBet1.betType = b
currentBet1.n = n
if (b < 7) {
currentBet1.text = betTypes[b] + ": " + bet + "g"
currentBet1.text = betTypes[b] + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g"
} else {
currentBet1.text = betTypes[b] + " " + (n + 1) + ": " + bet + "g"
currentBet1.text = betTypes[b] + " " + (n + 1) + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g"
}
} else {
currentBet2.betType = b
currentBet2.n = n
if (b < 7) {
currentBet2.text = betTypes[b] + ": " + bet + "g"
currentBet2.text = betTypes[b] + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g"
} else {
currentBet2.text = betTypes[b] + " " + (n + 1) + ": " + bet + "g"
currentBet2.text = betTypes[b] + " " + (n + 1) + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g"
}
}
}

39
Results.qml Normal file
View file

@ -0,0 +1,39 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import roulette
GridLayout {
rowSpacing: 20
columnSpacing: 50
flow: GridLayout.TopToBottom
rows: 3
anchors {
/* These random IDs com from Results' parent*/
left: payoutButton.right
leftMargin: 30
top: roulette.bottom
topMargin: 20
}
Repeater {
model: 7
Text {
text: ""
Connections {
target: PlayerAreaModel
function onResults(name, n, payout) {
if (index + 1 == n && name != "") {
text = name + ": " + payout.toLocaleString(Qt.locale(), 'f', 0) + "g"
}
}
}
}
}
}

View file

@ -4,17 +4,19 @@ import QtQuick.Controls
import roulette /* this is importing the target "roulette-payout" defined in CMakeLists.txt */
Window {
height: 500
width: 1000
maximumHeight: 500
maximumWidth: 1000
minimumHeight: 500
minimumWidth: 1000
title: "Roulette Payout"
visible: true
Pane {
anchors.fill: parent
/* Exists exclusively to remove focus from TextFields by clicking anywhere else on the screen */
MouseArea {
anchors.fill: parent
onClicked: focus = true
}
@ -32,5 +34,73 @@ Window {
right: parent.right
}
}
Button {
id: payoutButton
onClicked: PlayerAreaModel.payout()
enabled: false
anchors {
left: roulette.left
bottom: parent.bottom
bottomMargin: 20
}
contentItem: Text {
text: "Payout"
font.pointSize: 15
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: {
if (enabled == true) {
"#000000"
} else {
"#555555"
}
}
}
background: Rectangle {
implicitWidth: 150
implicitHeight: 60
opacity: {
if (enabled == true && parent.pressed) {
0.5
} else if (enabled == true && parent.hovered) {
0.2
} else {
0.3
}
}
color: {
if (enabled == true) {
"#AAAAAA"
} else {
"#444444"
}
}
border.width: 0
}
Connections {
target: PlayerAreaModel
function onBetChanged() {
if (PlayerAreaModel.focusedPlayer == 0) {
payoutButton.enabled = true;
}
}
function onBetRemoved() {
if (PlayerAreaModel.focusedPlayer == 0) {
payoutButton.enabled = false;
}
}
}
}
Results {
}
}
}

View file

@ -8,7 +8,6 @@ Item {
LayoutMirroring.enabled: true
flow: GridLayout.TopToBottom
rows: 3
//rotation: 180
anchors {
right: parent.right

View file

@ -1,6 +0,0 @@
#include "StreetBetsModel.h"
StreetBetsModel::StreetBetsModel(QObject *parent)
{
}

View file

@ -1,14 +0,0 @@
#pragma once
#include <QQuickView>
#include <qqmlintegration.h>
#include <qtmetamacros.h>
#include <qobject.h>
class StreetBetsModel : public QObject {
Q_OBJECT
QML_ELEMENT
public:
explicit StreetBetsModel(QObject *parent = nullptr);
};