Title: | A Game for Human vs. Human or Human vs. AI |
---|---|
Description: | A game for two players: Who gets first four in a row (horizontal, vertical or diagonal) wins. As board game published by Milton Bradley, designed by Howard Wexler and Ned Strongin. |
Authors: | Matthias Speidel [aut, cre] |
Maintainer: | Matthias Speidel <[email protected]> |
License: | GPL-3 |
Version: | 1.5.1 |
Built: | 2024-12-17 06:31:51 UTC |
Source: | CRAN |
Help-Function for an AI
AImove(field, AIstrength, AIplayernumber)
AImove(field, AIstrength, AIplayernumber)
field |
matrix: the playing field |
AIstrength |
integer: strength of the AI - number of moves the AI will simulate? |
AIplayernumber |
integer: 0 or 1: should the AI be player 1 or player 2? |
the selected row
help-function which return the x-axis-value of the mouse when releasing the mouse button.
clicking(buttons, x, y)
clicking(buttons, x, y)
buttons |
the mouse buttons input. |
x |
the x-value of the mouse button. |
y |
the y-value of the mouse button. |
a rounded value for the x-coordinate
a function to check the mouse click input by the user
clickingXY(buttons, x, y)
clickingXY(buttons, x, y)
buttons |
the mouse buttons input. |
x |
the x-value of the mouse button. |
y |
the y-value of the mouse button. |
a Vector of the x and y coordinates of the mouse click
A function to show buttons, letting the player(s) decide what to do: show the winning field, play again or exit.
fbuttons(field, justsub, message, MACuser, rows, columns, AI, AIstrength, AIplayernumber, PlayerNames, PlayerColors)
fbuttons(field, justsub, message, MACuser, rows, columns, AI, AIstrength, AIplayernumber, PlayerNames, PlayerColors)
field |
matrix: the field. |
justsub |
boolean: should only be a subtitle plotted (below the winning field)? |
message |
character: a message to be plotted. |
MACuser |
boolean: on some non-mac computers this can be set to |
rows |
integer: how many rows shall the playing field have? |
columns |
integer: how many columns shall the playing field have? |
AI |
boolean: play against AI? |
AIstrength |
integer: strength of the AI - number of moves the AI will simulate? |
AIplayernumber |
integer: 0 or 1: should the AI be player 1 or player 2? |
PlayerNames |
array of characters: the players' names. |
PlayerColors |
vector of characters: the players' colors. |
help-function that checks whether the field is correct
FieldCorrect(column, field)
FieldCorrect(column, field)
column |
integer: the column chosen by the current player |
field |
matrix: the playing field. |
a boolean (TRUE
if the given column would be a valid move for the field given).
help-function which generates the playing-field
FieldGeneration(rows, columns)
FieldGeneration(rows, columns)
rows |
integer: how many rows shall the playing field have? |
columns |
integer: how many columns shall the playing field have? |
an empty matrix with rows and columns
a major-function which plots the current field, and if given a hint, which player has won
FieldPlot(field, message, PlayerColors)
FieldPlot(field, message, PlayerColors)
field |
matrix: the playing field |
message |
character: a message to be plotted. |
PlayerColors |
vector of characters: the players' colors. |
help-function that checks whether (at least) one of the four possibilities of winning is given
FieldWinCheck(field, player)
FieldWinCheck(field, player)
field |
matrix: the playing field. |
player |
integer: the current player. |
a boolean whether the player has won the match or not
Function to play FourScores
FourScores(rows = 6, columns = 7, AI = TRUE, AIstrength = rows * columns, AIplayernumber = 1, MACuser = TRUE, PlayerNames = c("AI", "Human"), getnewnames = FALSE, PlayerColors = c("green", "blue"), getnewcolors = FALSE)
FourScores(rows = 6, columns = 7, AI = TRUE, AIstrength = rows * columns, AIplayernumber = 1, MACuser = TRUE, PlayerNames = c("AI", "Human"), getnewnames = FALSE, PlayerColors = c("green", "blue"), getnewcolors = FALSE)
rows |
integer: how many rows shall the playing field have? |
columns |
integer: how many columns shall the playing field have? |
AI |
boolean: play against AI? |
AIstrength |
integer: strength of the AI - number of moves the AI will simulate? |
AIplayernumber |
integer: 0 or 1: should the AI be player 1 or player 2? |
MACuser |
boolean: on some non-mac computers this can be set to |
PlayerNames |
array of characters: the players' names. |
getnewnames |
boolean: should new names be asked for? |
PlayerColors |
vector of characters: the players' colors. |
getnewcolors |
boolean: should new colors be asked for? |
## Not run: FourScores(AI = T, AIstrength = 10, MACuser = T, getnewnames = F, getnewcolors = F) ## End(Not run)
## Not run: FourScores(AI = T, AIstrength = 10, MACuser = T, getnewnames = F, getnewcolors = F) ## End(Not run)
A function to get some colors
getColors(PlayerNames, PlayerColors, MACuser)
getColors(PlayerNames, PlayerColors, MACuser)
PlayerNames |
array of characters: the players' names. |
PlayerColors |
vector of characters: the players' colors. |
MACuser |
boolean: on some non-mac computers this can be set to |
a vector with the updated player colors
help-function which gets and returns the players' names
getPlayerNames(PlayerNames, MACuser)
getPlayerNames(PlayerNames, MACuser)
PlayerNames |
array of characters: the players' names. |
MACuser |
boolean: on some non-mac computers this can be set to |
a vector with the player names
help-function which "throws" the stone into the field and returns the new field
NewField(field, column, player)
NewField(field, column, player)
field |
matrix: the playing field. |
column |
integer: the column chosen by the current player. |
player |
integer: the current player. |
The updated field matrix.
a general help function to plot
painter(numberMatrix, colorArray)
painter(numberMatrix, colorArray)
numberMatrix |
a matrix with different integers showing which color to pick from the |
colorArray |
a character array with different names of colors to be used by the painter. |
resampling function
resample(x, ...)
resample(x, ...)
x |
a vector |
... |
other parameters |
a vector
Help function from ?sample
to overcome the "sample(ret, size = 1)" problem for length(ret) == 1
help-function which returns, the key on the keyboard which is being typed
typing(key)
typing(key)
key |
a keyboard input. |
the key pressed.