Notifications
Clear all

tic-tac-toe games based on HMI by using Arduino  


Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  

I have a stone touch display as well as an Arduino and I want to use this touch display to make a simple tic-tac-toe game.
I'm a newbie in this issue of programming, I've been using the code-shared by others for my projects, and this time I want to finish an independent project by myself. Can anyone provide me with some help or ideas, please?


Quote
MadMisha
(@madmisha)
Estimable Member
Joined: 1 year ago
Posts: 240
 
Posted by: @maxli

I have a stone touch display as well as an Arduino and I want to use this touch display to make a simple tic-tac-toe game.
I'm a newbie in this issue of programming, I've been using the code-shared by others for my projects, and this time I want to finish an independent project by myself. Can anyone provide me with some help or ideas, please?

I created a few games with python and then recreated them with TKinter for practice but I never thought of doing it on an arduino.

But your post is vague. What exactly do you need help with? What parts of your project are you unsure about?

 

If I was doing that, I would probably start with 3 arrays that represent the rows. Then I would create a function to test if someone won(going through all 8 possibilities). I would probably pass the last players character in as what to test. So if X just played, test all 8 to see if they won. I would probably have an array for the leaderboard as well that would display at the top.


ReplyQuote
robotBuilder
(@robotbuilder)
Prominent Member
Joined: 2 years ago
Posts: 812
 

@maxli
First you need to know how to interface the particular TFT LCD Touch Screen you have with an Arduino.
https://howtomechatronics.com/tutorials/arduino/arduino-tft-lcd-touch-screen-tutorial/

 

This post was modified 1 month ago by robotBuilder

ReplyQuote
Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  
Posted by: @madmisha
Posted by: @maxli

I have a stone touch display as well as an Arduino and I want to use this touch display to make a simple tic-tac-toe game.
I'm a newbie in this issue of programming, I've been using the code-shared by others for my projects, and this time I want to finish an independent project by myself. Can anyone provide me with some help or ideas, please?

I created a few games with python and then recreated them with TKinter for practice but I never thought of doing it on an arduino.

But your post is vague. What exactly do you need help with? What parts of your project are you unsure about?

 

If I was doing that, I would probably start with 3 arrays that represent the rows. Then I would create a function to test if someone won(going through all 8 possibilities). I would probably pass the last players character in as what to test. So if X just played, test all 8 to see if they won. I would probably have an array for the leaderboard as well that would display at the top.

Thank you for your reply and your advice. I may need a starting idea and I think you did a good job of pointing me in the right direction. By the way, can you tell me what the conditions for judging victory are judging? Judging the number of clicks within each row of the array?


ReplyQuote
Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  
Posted by: @robotbuilder

@maxli
First you need to know how to interface the particular TFT LCD Touch Screen you have with an Arduino.
https://howtomechatronics.com/tutorials/arduino/arduino-tft-lcd-touch-screen-tutorial/

 

Oh yes, that's right, the connection method you described in this article is very similar to my LCD, the LCD in the article looks 8pin, my LCD is also 8pin, I think I can learn something useful from here. I learned how to connect LCD and Arduino from their official website.

https://www.stoneitech.com/application/application-note/arduino-tutorial-for-beginners-ly-f2-of-seven-star-bug.html

Only the model is different, I use UNO, but I think it should be more or less the same, what do you think?


ReplyQuote
MadMisha
(@madmisha)
Estimable Member
Joined: 1 year ago
Posts: 240
 
Posted by: @maxli

Thank you for your reply and your advice. I may need a starting idea and I think you did a good job of pointing me in the right direction. By the way, can you tell me what the conditions for judging victory are judging? Judging the number of clicks within each row of the array?

The idea is that the current play field is held in those. Position 1 array index 0 would be the top left cell. If X played there, there would be an X. 

 

p1 = ["x", , "O"];
p2 = ["X", "X", "X"];
p3 = ["O", "O", ];

 

So the test would be if you are checking for X because they just made a move, is p1[0], p1[1] and p1[2] all X? That would be no so test the same for p2 array and you have the result of true. You would also need to check p1[0], p2[0] and p3[0] as well as the diagonal. There should be 8 total.

My style would be to get the backbone of the game working first then worry about the display/interface but there is nothing wrong with starting there. I just like to have something to display when I get to that. You can always fill those arrays like I did above so you can mess around with the display. It helps in getting placement and not having to rewrite things later.

 

Later, I would set it to wait for touch and depending on what section of the screen was touched, and who's turn it was, write to the array. Then run the function to check for a win and if there was not a win, change player and update display.


ReplyQuote
Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  
Posted by: @madmisha
Posted by: @maxli

Thank you for your reply and your advice. I may need a starting idea and I think you did a good job of pointing me in the right direction. By the way, can you tell me what the conditions for judging victory are judging? Judging the number of clicks within each row of the array?

The idea is that the current play field is held in those. Position 1 array index 0 would be the top left cell. If X played there, there would be an X. 

 

p1 = ["x", , "O"];
p2 = ["X", "X", "X"];
p3 = ["O", "O", ];

 

So the test would be if you are checking for X because they just made a move, is p1[0], p1[1] and p1[2] all X? That would be no so test the same for p2 array and you have the result of true. You would also need to check p1[0], p2[0] and p3[0] as well as the diagonal. There should be 8 total.

My style would be to get the backbone of the game working first then worry about the display/interface but there is nothing wrong with starting there. I just like to have something to display when I get to that. You can always fill those arrays like I did above so you can mess around with the display. It helps in getting placement and not having to rewrite things later.

 

Later, I would set it to wait for touch and depending on what section of the screen was touched, and who's turn it was, write to the array. Then run the function to check for a win and if there was not a win, change player and update display.

If I want to keep everything simple, I think the first press on the screen must be o. The next press on the screen that needs to be reversed is x and then keep doing this cycle, I do not know if it is feasible.


ReplyQuote
MadMisha
(@madmisha)
Estimable Member
Joined: 1 year ago
Posts: 240
 
Posted by: @maxli

If I want to keep everything simple, I think the first press on the screen must be o. The next press on the screen that needs to be reversed is x and then keep doing this cycle, I do not know if it is feasible.

I don't think it would really matter. You should probably have a boolean to keep track of who's turn it is. Pick what character is true and false, but keep it consistent. That way you can use a != with itself to change turns. You could even use that as a reference for the check.


ReplyQuote
Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  
Posted by: @madmisha
Posted by: @maxli

If I want to keep everything simple, I think the first press on the screen must be o. The next press on the screen that needs to be reversed is x and then keep doing this cycle, I do not know if it is feasible.

I don't think it would really matter. You should probably have a boolean to keep track of who's turn it is. Pick what character is true and false, but keep it consistent. That way you can use a != with itself to change turns. You could even use that as a reference for the check.

Okay, thanks a lot, I'll look into it more, and I'll keep updating when I've made progress!


ReplyQuote
robotBuilder
(@robotbuilder)
Prominent Member
Joined: 2 years ago
Posts: 812
 

@maxli
I'm a newbie in this issue of programming, I've been using the code-shared by others for my projects, and this time I want to finish an independent project by myself. Can anyone provide me with some help or ideas, please?

Rather hard to know where to start if we don't know how much programming skills you already have?

Assuming you are using the Arduino IDE you can test your code using the Arduino Monitor to enter moves and display the results.  Entering a move would be in a function and displaying the board would be another function. Then all you have to do is recode the getMove() function to get a move from the touch screen rather than a move entered via the keyboard and recode the displayBoard() function to draw the board on the screen rather than print it out on the Arduino monitor. The rest of the code, the algorithm that plays the game, would remain the same.

You might search the net for examples of this very project.

 


ReplyQuote
Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  
Posted by: @robotbuilder

@maxli
I'm a newbie in this issue of programming, I've been using the code-shared by others for my projects, and this time I want to finish an independent project by myself. Can anyone provide me with some help or ideas, please?

Rather hard to know where to start if we don't know how much programming skills you already have?

Assuming you are using the Arduino IDE you can test your code using the Arduino Monitor to enter moves and display the results.  Entering a move would be in a function and displaying the board would be another function. Then all you have to do is recode the getMove() function to get a move from the touch screen rather than a move entered via the keyboard and recode the displayBoard() function to draw the board on the screen rather than print it out on the Arduino monitor. The rest of the code, the algorithm that plays the game, would remain the same.

You might search the net for examples of this very project.

 

My Arduino board is Arduino Uno

I will search for more examples of this.


ReplyQuote
Maxli
(@maxli)
Active Member
Joined: 3 months ago
Posts: 19
Topic starter  

Through everyone's help and my own internet search for cases, I have finished the project, and those who are interested can watch the video I posted.


ReplyQuote