Python Projects
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
Yes, we have to find a winner, but with LiveCode we can do that in a way that
more closely resembles real life to the way it is done in Python.
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
The grey part of the LiveCode stack will be hidden to the end-user.
The script in the cells of the grid have been modifed in 2 ways:
Code: Select all
on mouseUp
if fld "f1" is empty then
if the shiftKey is down then
set the textColor of fld "f1" to red
put "O" into me
else
set the textColor of fld "f1" to black
put "X" into me
end if
add 1 to fld "fFILLED"
--
if fld "fFILLED" contains "9" then
send "mouseUp" to button "WIN"
end if
--
end if
end mouseUp
Code: Select all
add 1 to fld "fFILLED"
is updated in the field "fFILLED" [that's the field in the grey area of the stack].
Code: Select all
if fld "fFILLED" contains "9" then
send "mouseUp" to button "WIN"
end if
(which, at the moment contains no code)
Code: Select all
on mouseUp
--the winner will be worked out here
end mouseUp
where the winner will be calculated.
- Attachments
-
- Nowts & Crosses 3.livecode.zip
- Here we go.
- (8.26 KiB) Downloaded 187 times
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
There are 8 ways either side can win the game.
- -
4 of which can be determined by initially finding out
if the central cell (field "f5") is occupied.
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
We'll start by setting up 2 pictures, here called
'OWIN' and 'XWIN' respectedly.
[These were made inwith LiveCode, but they could, just as easily, be imported.]
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
On the basis of the pictorial analysis of winning patterns we can write code in
the scriptEditor of the 'WIN' button:
At which point the exercise is finished.
the scriptEditor of the 'WIN' button:
Code: Select all
on mouseUp
wait 30 ticks
--X--
if fld "f5" contains "X" then
if fld "f4" contains "X" and fld "f6" contains "X" then
set the vis of img "XWIN" to true
end if
if fld "f2" contains "X" and fld "f8" contains "X" then
set the vis of img "XWIN" to true
end if
if fld "f1" contains "X" and fld "f9" contains "X" then
set the vis of img "XWIN" to true
end if
if fld "f3" contains "X" and fld "f3" contains "X" then
set the vis of img "XWIN" to true
end if
end if
---
if fld "f1" contains "X" then
if fld "f2" contains "X" and fld "f3" contains "X" then
set the vis of img "XWIN" to true
end if
if fld "f4" contains "X" and fld "f7" contains "X" then
set the vis of img "XWIN" to true
end if
end if
---
if fld "f9" contains "X" then
if fld "f3" contains "X" and fld "f6" contains "X" then
set the vis of img "XWIN" to true
end if
if fld "f7" contains "X" and fld "f8" contains "X" then
set the vis of img "XWIN" to true
end if
end if
--O--
if fld "f5" contains "O" then
if fld "f4" contains "O" and fld "f6" contains "O" then
set the vis of img "OWIN" to true
end if
if fld "f2" contains "O" and fld "f8" contains "O" then
set the vis of img "OWIN" to true
end if
if fld "f1" contains "O" and fld "f9" contains "O" then
set the vis of img "OWIN" to true
end if
if fld "f3" contains "O" and fld "f3" contains "O" then
set the vis of img "OWIN" to true
end if
end if
---
if fld "f1" contains "O" then
if fld "f2" contains "O" and fld "f3" contains "O" then
set the vis of img "OWIN" to true
end if
if fld "f4" contains "O" and fld "f7" contains "O" then
set the vis of img "OWIN" to true
end if
end if
---
if fld "f9" contains "O" then
if fld "f3" contains "O" and fld "f6" contains "O" then
set the vis of img "OWIN" to true
end if
if fld "f7" contains "O" and fld "f8" contains "O" then
set the vis of img "OWIN" to true
end if
end if
end mouseUp
- Attachments
-
- Nowts & Crosses 4.livecode.zip
- Here's the stack.
- (22.44 KiB) Downloaded 174 times
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
One of the SHORTCOMINGS of this stack is that it does NOT check
for a WIN until all 9 of the cells are filled, so this should be changed:
- -
You will see that the condition about '9' is now redundant.
- -
for a WIN until all 9 of the cells are filled, so this should be changed:
- -
You will see that the condition about '9' is now redundant.
- -
Last edited by richmond62 on Wed Nov 10, 2021 1:14 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
You will also realise that, now, the field "fFILLED" is also unnecessary
and can be deleted, as well as any code refering to it:
- -
and can be deleted, as well as any code refering to it:
- -
- Attachments
-
- Nowts & Crosses 5.livecode.zip
- Here's the stack.
- (22.36 KiB) Downloaded 187 times
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
The next step is to set up the Noughts and Crosses game so the end-user can play
against the computer.
Obviously this will need quite a lot of code jiggling.
against the computer.
Obviously this will need quite a lot of code jiggling.
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
The FIRST thing we have to do is REMOVE the chance of the end-user
inserting an 'O' into a cell:
- -
Then we'll have a BUTTON to allow the computer to play against the end-user:
- -
inserting an 'O' into a cell:
- -
Then we'll have a BUTTON to allow the computer to play against the end-user:
- -
Code: Select all
on mouseUp
put 1 into CELL
put 0 into STOPPER
repeat until CELL > 9
put random(9) into RANDY
if STOPPER contains 0 then
if fld ("f" & RANDY) is empty then
set the textColor of fld ("f" & RANDY) to red
put "O" into fld ("f" & RANDY)
put 256 into STOPPER
end if
end if
add 1 to CELL
end repeat
end mouseUp
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
We then have to CALL the MACHINE PLAY button every time
the end-user plays:
-
the end-user plays:
Code: Select all
on mouseUp
if fld "f3" is empty then
set the textColor of fld "f3" to black
put "X" into me
end if
--
send "mouseUp" to button "MACHINE PLAY"
--
send "mouseUp" to button "WIN"
--
end mouseUp
- Attachments
-
- Nowts & Crosses 6.livecode.zip
- Here's the stack.
- (30.34 KiB) Downloaded 186 times
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
I am not entirely sure why, having been using Python, the next section works with SCRATCH:
- -
The resources referred to see inaccessible:
- -
The resources referred to see inaccessible:
NOT, frankly, that that should stop us.Add the Rudolph sprite to the project (use the resources/Rudolph.png
file)
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
So, our first 'problem' is to import a daft reindeer image, a sky-type background, and script things so that
the reindeer image FOLLOWS the MOUSE.
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
At the moment the image of a deer contains the following script:
Code: Select all
on mouseDown
grab me
end mouseDown
- Attachments
-
- Christmas.livecode.zip
- Here's the stack.
- (187.86 KiB) Downloaded 155 times
-
- Livecode Opensource Backer
- Posts: 9446
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Python Projects
Theoretical, teacher-ish pause time.
than that from SCRATCH to Python.
I learnt a dialect of BASIC in 1977 after having learnt FORTRAN IV, and can honestly state that I became far more
competent in BASIC than I ever was in FORTRAN exactly because it was developed with beginners in mind.
LiveCode's ancestry goes back to something that was conceived of as the non-programmer's programming thing,
and to a very large extent it has preserved that, while having a considerable amount of "other stuff" on top.
Interestingly enough,
way around, yet they are not that similar.
Indeed, but you have to start somewhere, and preferably somewhere that has a shallower learning curveAnd outside of our little corner of the world, most programmers are polyglots.
than that from SCRATCH to Python.
I learnt a dialect of BASIC in 1977 after having learnt FORTRAN IV, and can honestly state that I became far more
competent in BASIC than I ever was in FORTRAN exactly because it was developed with beginners in mind.
LiveCode's ancestry goes back to something that was conceived of as the non-programmer's programming thing,
and to a very large extent it has preserved that, while having a considerable amount of "other stuff" on top.
Interestingly enough,
I have found that children (9-12) have no obvious problems moving from BBC BASIC to LiveCode or the otherthe commonalities of C-style OOP languages
way around, yet they are not that similar.
-
- VIP Livecode Opensource Backer
- Posts: 9853
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Python Projects
It would seem the more useful question for addressing LC as a bridge from Scratch to anything else is:richmond62 wrote: ↑Wed Nov 10, 2021 8:14 pmI have found that children (9-12) have no obvious problems moving from BBC BASIC to LiveCode or the other
way around, yet they are not that similar.
How did those kids become proficient in BBC BASIC?
A good second question might be:
How do kids already proficient in BASIC do when learning Python vs learning LC?
BASIC is kinda funky. Can't imagine either LC or Python not being a welcome change.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn