V1 Lotto - get the array matching working
The original Lotto problem is more detailed, but as this is VERSION 1, our problem is much more limited.
Stages of the planning process are:
1. Defining the problem - Business need:
2. Planning and Designing the solution:
5. Maintaining:
(Note: this page is copied from a school OneNote file and some links below may not work)
Features of this version:
· Brute force, repetitive code to just "get it working"
· JUST 1 DRAW when the problem states 1,000 draws
· Use of 1 dimensional arrays of integers
· Use of the IF / ELSE control structure
· Use of the FOR / NEXT control structure (pre-test loop)
· HARD CODING of variable values for testing of the "array match" module
· Use of RANDOM number function
o In PASCAL, the function will return the same numbers each time
· Thorough TESTING of the array handling
o JavaScript loads the computer array as text values
· No VALIDATION - this code can easily be broken with the entry of text values
· Limited "maintainability" for possible changes in the number of balls in a Lotto draw
· Limited "re-usability" for possible changes in the number of balls in a Lotto draw
JavaScript code is visible on GitHub at: https://github.com/bwattle/20-Lotto
Web pages are visible here: https://bwattle.github.io/20-Lotto/.
Pseudocode conventions:
· Assume: PRINT("message") is either:
· Displays a command line
· Loads a text box
· Triggers a pop-up message box
· Assume: randomlnt(low,high) returns a random integer between low and high inclusive.
· Assume: sort(array)sorts from smallest to biggest
Pseudo V1: (1 game - check the array comparison - true/false case)
(use commenting to test both cases)
BEGIN lotto
myNumbers = [8, 10, 18, 26, 30, 35] // hard code
\\ lottoNums = [8, 10, 18, 26, 30, 35] // for TRUE test
n1 = randomInt(1, 40)
n2 = randomInt(1, 40)
n3 = randomInt(1, 40)
n4 = randomInt(1, 40)
n5 = randomInt(1, 40)
n6 = randomInt(1, 40)
lottoNums = [n1, n2, n3, n4, n5, n6]
//lottoNums = [n1, n2, n3, n4, n5, n6] //for FALSE test
IF myNumbers = lottoNums THEN //term by term in some languages
PRINT("You win!")
ELSE
PRINT("You lose!")
ENDIF
END lotto
We will combine the "Structured Approach" with the "Prototype approach"
approach and complete this cycle many times:
1. Defining the problem - Business need:
o For 6 "hard coded" numbers between 1 and 40 inclusive, the programme will:
o There will be an identical set of numbers for testing the array comparison module (or sub-routine)
o Generate 1 set of 6 random numbers between 1 and 40 inclusive
o Match the 6 hard coded #'s with
· identical array - TRUE case
· the random number array - FALSE case
· state message, either:
§ "You won"
§ "You didn't win"
2. IPO chart to analyse the problem
INPUT |
PROCESS |
OUTPUT |
My #'s |
Hard coded |
String output - user (a,b,c,d,e,f) |
Identical #'s |
Hard coded |
String output - computer (a,b,c,d,e,f) |
No1
No2
No3
No4
No5
No6 |
Add the 6 ascending "hard coded" numbers to an array and compare them with another array of 6 computer generated random numbers
(this is basic because it is version 1) |
String output - computer (a,b,c,d,e,f)
Print (display)
"You win" or
"You lose" |
2. Planning and Designing the solution:
o Processing Steps:
o Declare the "myNumbers" array and assign 6 values
o Declare the "lottoNums" array and assign 6 values
o Compare the 2 arrays
o Display win/lose message
2. Break into modules if possible
o User 6 numbers into myNumbers array
o Computer 6 numbers into lottoNums array
o Compare arrays
o Display message
3. Variables:
DATA DICTIONARY Data dictionary: example here: Data Dictionary - versions
Variable |
Data
Type |
Entry
Calculation
Constant? |
Size
Bytes |
Description of Variable |
Example |
User No
1 .. 6 |
Integer |
Hard coded |
2 |
Whole number |
31 |
Computer No1 .. 6 |
Integer |
Random generation |
2 |
Whole number |
24 |
myNumbers |
Array(6 integers) |
Loaded by computer |
12 |
6 element array |
(6, 5, 3, 1, 8, 7) |
lottoNums |
Array(6 integers) |
Loaded by computer |
12 |
6 element array |
(7, 9, 13, 11, 28, 17) |
arrMatch |
Boolean |
Calculated |
1 bit |
Match y/n |
True/False |
arrAsText |
String |
Calculated |
Huge |
Block of text with () , and numbers and line breaks for display in text box |
(7, 9, 13, 11, 28, 17)
(7, 9, 13, 11, 28, 17) |
|
|
|
|
|
|
Form objects:
OBJECT DICTIONARY
Control
Name |
Data
Type |
Object
Type |
Size for display |
Description |
txtU1..6 |
Integer |
6 Text boxs |
4 |
Enter 2 digit # |
txtC1..6 |
Integer |
6 Text boxs |
4 |
Enter 2 digit # |
txtMatchMsg |
String |
Text box |
35 cols x 1 row |
Win/lose message |
txtArrayList |
String |
List box |
35 cols x 10 rows |
Display up to 1000 arrays of random numbers |
btnLottoDraw |
Click event |
Button |
35 cols x 1 row |
Click for a draw |
d. System modelling tools for the Algorithms:
i. Flow Chart - table below from P116 of the text
b. Pseudocode:
BEGIN
READ No1
READ No2
READ No3
Total = No1 + No2 + No3
DISPLAY Total
END
Code in Pascal, Python, VB and JavaScript - preferably all 4!
iii. Desk checks and walk throughs to test the algorithm
Statement |
Test1 |
Test2 |
Test3 |
READ No1 |
2 |
5 |
|
READ No2 |
5 |
89 |
|
READ No3 |
7 |
5643 |
|
Total = No1 + No2 + No3 |
2+5+7=14 |
5+89+5643 = 5737 |
|
DISPLAY Total |
14 |
5737 |
|
iv. Structure Charts: - modules or sub-routines
v. Metalanguage descriptions definitions here: EBNF & Railroad
Examples here: Syntax in 3 languages
Related to this project:
iii. JS EBNF and Railroad
iii. Implementation (Building):
Python - True case
Python - False case - sort not working!
Pascal - syntax error caused by the word "don't" - Why?
Pascal - True case - note that the 6 loops did NOT return a FALSE!
Pascal - False case - all loops would return FALSE:
Pascal - additional FALSE to check random numbers are different:
VB True case
Form view - not sure of the best form layout yet!
VB False case - random numbers added in:
Form view - not sure of the best form layout yet!
Full code visible on GitHub at: https://github.com/bwattle/20-Lotto
Working site visible here: https://bwattle.github.io/20-Lotto/.
VS False case - full code to come:
4. Testing & Evaluation:
a. Random number generation NOT done in JavaScript
5. Maintaining:
a. The client