Compare commits
7 Commits
528422822d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ef616df92 | |||
| 41c53e86ec | |||
| 54666fd55c | |||
| 4c74a07eb6 | |||
| f34be20aa1 | |||
| 2333762f46 | |||
|
|
3ec015142d |
@@ -1,6 +1,8 @@
|
|||||||
Game to have computer guess what number the user is thinking of.
|
Game to have computer guess what number the user is thinking of.
|
||||||
|
|
||||||
### Goals
|
Going to try Lua and bash scripts. See which one I get along better with.
|
||||||
|
|
||||||
|
## Goals
|
||||||
|
|
||||||
#### ABSOLUTELY NO AI!!!!
|
#### ABSOLUTELY NO AI!!!!
|
||||||
Rules command
|
Rules command
|
||||||
@@ -11,3 +13,4 @@ Variable number. 'Between 1 and a user selected number'
|
|||||||
maybe 30% ?
|
maybe 30% ?
|
||||||
Play Again? dialog
|
Play Again? dialog
|
||||||
|
|
||||||
|
## Outline
|
||||||
|
|||||||
21
bash/randTest.sh
Executable file
21
bash/randTest.sh
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# set script restart
|
||||||
|
script=$(readlink -f "$0")
|
||||||
|
|
||||||
|
# Select number
|
||||||
|
echo "Pick a number:"
|
||||||
|
read num
|
||||||
|
|
||||||
|
# Output response
|
||||||
|
echo "The random number is $((1 + $RANDOM % $num))."
|
||||||
|
|
||||||
|
# Ask to run again
|
||||||
|
|
||||||
|
echo "Run script again (yes/no)?"
|
||||||
|
read answer
|
||||||
|
if [ "$answer" = yes ]
|
||||||
|
then exec "$script"
|
||||||
|
fi
|
||||||
|
echo "Exiting"
|
||||||
|
exit 0
|
||||||
0
delete.test
Normal file
0
delete.test
Normal file
BIN
lua/Notes/help1.png
Normal file
BIN
lua/Notes/help1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
10
lua/randTest.lua
Normal file
10
lua/randTest.lua
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
io.write("Pick a number: ")
|
||||||
|
local number = io.read("*n")
|
||||||
|
local randnum = math.random(1, number)
|
||||||
|
print("The number is ", randnum)
|
||||||
|
-- ask to rerun script
|
||||||
|
print("Run again (y/n)?")
|
||||||
|
local cmd = io.read()
|
||||||
|
if cmd == "y" then
|
||||||
|
dofile("randTest.lua")
|
||||||
|
else end
|
||||||
26
lua/randTestExperiment.lua
Normal file
26
lua/randTestExperiment.lua
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- Assistance from a friend
|
||||||
|
|
||||||
|
-- Instantiate all the things
|
||||||
|
local run = true
|
||||||
|
local cmd, number, randnum
|
||||||
|
|
||||||
|
-- Start a loop
|
||||||
|
while run == true do
|
||||||
|
-- Get the users initial number
|
||||||
|
io.write("Pick a number: ")
|
||||||
|
number = io.read("*n")
|
||||||
|
|
||||||
|
-- Do some mathemagic
|
||||||
|
-- randnum = math.random(1, number)
|
||||||
|
print("The random number is ", math.random(1, number))
|
||||||
|
|
||||||
|
-- Ask to rerun script
|
||||||
|
io.read()
|
||||||
|
print("Run again (Y/n)?")
|
||||||
|
cmd = io.read("*l")
|
||||||
|
|
||||||
|
-- Exit if the user doesn't want to go again
|
||||||
|
if string.lower(cmd) ~= "y" then
|
||||||
|
run = false
|
||||||
|
end
|
||||||
|
end
|
||||||
26
lua/randTestHelped.lua
Normal file
26
lua/randTestHelped.lua
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- Assistance from a friend
|
||||||
|
|
||||||
|
-- Instantiate all the things
|
||||||
|
local run = true
|
||||||
|
local cmd, number, randnum
|
||||||
|
|
||||||
|
-- Start a loop
|
||||||
|
while run == true do
|
||||||
|
-- Get the users initial number
|
||||||
|
io.write("Pick a number: ")
|
||||||
|
number = io.read("*n")
|
||||||
|
|
||||||
|
-- Do some mathemagic
|
||||||
|
randnum = math.random(1, number)
|
||||||
|
print("The random number is ", randnum)
|
||||||
|
|
||||||
|
-- Ask to rerun script
|
||||||
|
io.read()
|
||||||
|
print("Run again (Y/n)?")
|
||||||
|
cmd = io.read("*l")
|
||||||
|
|
||||||
|
-- Exit if the user doesn't want to go again
|
||||||
|
if string.lower(cmd) ~= "y" then
|
||||||
|
run = false
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user