2017년 7월 26일 수요일

Canvas, List: Tic-Tac-Toe using multiple canvases


This game could have been more easily done using labels in a grid screen arrangement, but I wanted to be able to turn the letters in the splash screen at different angles in a simple animation (can't do that with labels). So this is the result. I learned some things along the way. I am hoping that some of you developers out there will be able to use some of this for your own AI projects.

I would say that the most interesting thing about this project is how to model the game in an AI app. After each play (an X or O) the app must check the rules to see if the player won the game.

I set up a list of component id's for each canvas in the 9-canvas grid. These component id's are used to access each canvas's DrawTextAtAngle tool, Clear, FontSize, PaintColor Width, Height and BackGroundColor. (The For each loop is a good block to read or set these values.)

The canvas components appear in the Components list in positions 1-9, 1-3 being the top row, 4-6 the middle row and 7-9 the bottom row.
In addition, I needed to know what letter was on what canvas in order to determine where an open spot was for a play and to check if a player had won or if the game was a tie,
so I created the Letters list to hold the current letter (X or O) in each canvas, or empty text if it was open.

I created a Combinations nested list which contains the 8 triplet combinations that indicate a win. It would look like ((1 2 3) (4 5 6) (7 8 9) (1 4 7) (2 5 8) (3 6 9) (1 5 9) (3 5 7)).
I then looped through the 8 possible combinations to see if the current player's letter was in all 3 of the canvases. the blocks for doing this are shown below.

The Intro Screen below loops through each of the 9 canvases putting random paintcolor and backgroundcolor and turning the intro text randomly between +/- 10 degrees.


Single player (playing against the computer):
Selecting the Two players option (the Mute Sound mutes the 'Host's' voice and sound effects):
Sarah won this game...
List of canvas components (count 'em --9)
Combinations (nested) list contains the 8 triplets that indicate a win. Note that these number indicate the position of the canvas component in the Components list.
The next group of blocks will do the lookups in the Letters list to see if the player won...

These blocks loop through the 8 possible win combinations....
All I can say is this was a LOT of work for such a simple game, but it was worth it :)
Project is attached...

--

Strategic TIC TAC TOE


Strategic TIC TAC TOE OVERVIEW:

This is the classic game of X's and O's where each player tries to get three of their marks in a row, column or diagonally in a grid of nine squares.

For this example, the player (you) plays against the app using your mark (X).

While you can use whatever strategy you wish during game play, the app must follow the one it is programmed to follow. I programmed it to use the following strategy:

In this particular version of the game, the player (you) allways goes first and uses the X mark to play. If the player has three X's in a row, column or diagonally then he wins. End of game.

If the player's play did not result in a win then it is the app's turn.

The app checks if all of the squares have been filled before attempting to play. If no plays are available then the game is a tie. End of game.

Otherwise, the app can make a play so...

The app will look for all winning plays and if any are available, select one at random to win the game. End of game.

If no winning play is available then continue...

The app will look to see if the player is one mark away from any winning plays and if so, block one of those plays at random by putting the app mark (O) there instead.

If the player has no winning plays to be blocked by the app then continue...

If the app finds any rows, columns or diagonals which don't contain the Player's mark then it picks an empty button from one of these to make a play with preference for the center button first, followed by any corner button then any other empty button.


What is left for App to make a play is one or more rows, columns or diagonals that have a Button containing Player's mark and either one empty button and one containing App's mark or two empty buttons.
The App chooses one of the empty buttons with a preference for the center button first, followed by any corner button then any other button.

Now play goes back to the player.
---

The App's strategy is shown in the procedure block below:

 

Most major blocks contain comments that describe their function in the app.
Project aia file is attached.


--
nice to meeting you

--
Really terrific.

How you did not miss anything from those many complicated blocks.
Congratulations.
App is running fine but getting defeated by the user.

--
If the app maken optimaal moven, the outcome should always be a draw, unless the player is really stupid.

--

Filling out a textbox and then emailing the results


I'd like the user to fill out a textboxes, pick a number from a list, and then have the results emailed to a specific email address. I think I'm missing something.



--
Look at the mail example here Using the Activity Starter Component  ... it is low in the page.

Where the example uses make a list  blocks , use your Name_label.text , Age_label.text  puzzle pieces.  For the uri block use a Join.

Did that work?

--
I've tried a few things are have received the following errors: 

⦁ Argument to Extras should be a list of pairs
⦁ Unsupported action
⦁ Error 602

Here's a screenshot of what I have. Not sure what I'm doing wrong.


--
Are you using a device or the emulator.? The emulator won't run that code.
I have similar code that works using a device but not the emulator.  It has only two makelist blocks so the additional blocks you use are possibly your issue.

For the second makelist block consider using a join block to display weight pain and age all at one time?

Try it.  I am too busy at the moment to provide the code but will do so later.    Perhaps try Taifun's solution?

--
I was using an emulator. On my device, I got it to work, but it only sent an email that said "How old are you?" 

--
I was using an emulator. On my device, I got it to work, but it only sent an email that said "How old are you?" I'll try your suggestion about joining the blocks and also Taifun's solution. 

--
Thanks, Taifun. I'll give it a try and let you know how it worked out!

--
This works:
...an entire text message can be formatted using the Join and the  ∖n control character.  Good luck with your project.

--

PDF file can not display


Need help, i try to import pdf file from google drive to sd card and success but the problem is the file can not be display, any suggestion for this problem? 



--
PDF-files aren´t picture files.
To display a pdf, you can either use Taifun´s PDF extension or Taifun´s Snippet using ActivityStarter.

pdf.aia

--
Thank a lot Mr. Nico


--

sorry i make mistake from the first time i have use this aia program to display a pdf file but the file that i have download before from google drive can not display, maybe any suggestion?


--
The error in the screenshot is the same as in your first post. Perhaps you´ve forget to update it?
Are there still errors?

--
listFileNameDrive should be a list of ids and not filenames, see also Q3 here https://puravidaapps.com/filebyfile.php#q

--
Thank a lot Mr. Taifun its work and also thank to Mr. Nico

--