# Tic Tac Toe (For Fun)

2968 lượt xem
Hello All,

I think all of you know the game "Tic Tac Toe" :) This time I tried to make this game, and also I tried to share an example to develop a game script in Pine. Just for fun ;)

Tic Tac Toe Game Rules:
1. The game is played on a grid that's 3 squares by 3 squares.
2. You are "O", the computer is X. Players take turns putting their marks in empty squares.
3. if a player makes 3 of her marks in a row (up, down, across, or diagonally) the he is the winner.
4. When all 9 squares are full, the game is over (draw)

So, how to play the game?
- The player/you can play "O", meaning your mark is "O", so Xs for the script. please note that: The script plays with ONLY X
- There is naming for all squears, A1, A2, A3, B1, B2, B3, C1, C2, C3. you will see all these squares in the options.
- also You can set who will play first => "Human" or "Computer"

if it's your turn to move then you will see "You Move" text, as seen in the following screenshot. for example you want to put "O" to "A1" then using options set A1 as O

How the script play?
it uses MinMax algorithm with constant depth = 4. And yes we don't have option to make recursive functions in Pine at the moment so I made four functions for each depth. this idea can be used in your scripts if you need such an algorithm. if you have no idea about MinMax algorithm you can find a lot of articles on the net :)
The script plays its move automatically if its turn to play. you will just need to set the option that computer played (A1, C3, etc)

if it's computer turn to play then it calculates and show the move it wants to play like "My Move : B3 <= X" then using options you need to set B3 as X

Also it checks if the board is valid or not:

I have tested it but if you see any bug let me know please

Enjoy!
Phát hành các Ghi chú: "Players" option added. You can play vs a friend or computer :)

Player option:
==> "Human vs Computer"
==> "Human vs Human"
Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
If you find my works useful, please consider a donation
BTC: 19qDW9AShZhBZsGuXcgRzam5Fbpc3EU8EV
ETH: 0x39c8552371b9b7f4e324197af460ba8bc8e18ef9

## Bình luận

Looool. Brilliant!
Phản hồi
cragum123
@cragum123, thank you :))))))
Phản hồi
Hocam lütfen Türkçe açıklamasını da yazın başarılar
Phản hồi
Nice distraction when watching charts :-)
Phản hồi
jurlvarg
@jurlvarg, I think so too :)))
Phản hồi
LonesomeTheBlue
@LonesomeTheBlue, next one is chess? :-D
Phản hồi
jurlvarg
@jurlvarg, I have chess engine in C, Why not after we have recursive functions in Pine :)
Phản hồi
LonesomeTheBlue
@LonesomeTheBlue, That would be a real pleasure... It would be awesome to see Pine grow to something similar to Python :-)
Phản hồi
jurlvarg
@jurlvarg, Pine grows very very fast, Pine Team really work hard and making the Pine great. All thanks to Pine Team!
Phản hồi
LonesomeTheBlue
@LonesomeTheBlue, Indeed .. the Pine Team is doing a great job! And you're part of it so cheers to you as well :-)
Phản hồi
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Tin nhắn riêng Trò chuyện Đăng xuất