Cov txheej txheem:

Arduino Touch Tic Tac Toe Game: 6 Kauj Ruam (nrog Duab)
Arduino Touch Tic Tac Toe Game: 6 Kauj Ruam (nrog Duab)

Video: Arduino Touch Tic Tac Toe Game: 6 Kauj Ruam (nrog Duab)

Video: Arduino Touch Tic Tac Toe Game: 6 Kauj Ruam (nrog Duab)
Video: Wie aus einem Arduino mit Touchdisplay eine Video-Game Konsole wird 2024, Kaum ib hlis
Anonim
Image
Image
Arduino Touch Tic Tac Toe Game
Arduino Touch Tic Tac Toe Game
Arduino Touch Tic Tac Toe Game
Arduino Touch Tic Tac Toe Game
Arduino Touch Tic Tac Toe Game
Arduino Touch Tic Tac Toe Game

Nyob zoo cov phooj ywg zoo siab txais tos rau lwm qhov kev qhia Arduino! Hauv qhov kev qhia ntxaws no peb tab tom tsim Arduino Tic Tac Toe game. Raws li koj tuaj yeem pom, peb tab tom siv lub vijtsam kov thiab peb tabtom tawm tsam lub computer. Kev ua si yooj yim zoo li Tic Tac Toe yog qhov qhia zoo rau kev ua si game thiab Artificial Intelligence. Txawm hais tias peb yuav tsis siv Artificial Intelligence Algorithms hauv qhov kev ua si no, peb yuav nkag siab tias vim li cas Artificial Intelligence Algorithms yuav tsum muaj nyob hauv kev ua si nyuaj dua.

Tsim kev ua si rau Arduino tsis yooj yim thiab xav tau sijhawm ntau. Tab sis peb tuaj yeem tsim qee qhov kev ua si yooj yim rau Arduino vim tias nws lom zem thiab nws yuav tso cai rau peb tshawb xyuas qee cov ncauj lus kom zoo dua qub, zoo li Artificial txawj ntse. Nws yog qhov kev kawm paub zoo thiab thaum kawg koj yuav muaj kev ua si zoo rau cov menyuam!

Cia tam sim no tsim txoj haujlwm no.

Kauj Ruam 1: Tau Txais Txhua Qhov

Image
Image
Qhov 2.8
Qhov 2.8

Cov ntu xav tau txhawm rau txhawm rau tsim txoj haujlwm no yog cov hauv qab no:

Ib Arduino Uno ▶

A 2.8 "Touch Screen ▶

Tus nqi ntawm txoj haujlwm yog tsawg heev. Nws tsuas yog 15 $

Ua ntej sim tsim txoj haujlwm no thov saib cov vis dis aus Kuv tau npaj txog qhov kov cov khoom. Kuv tau txuas nws hauv cov lus qhia no. Nws yuav pab koj nkag siab cov cai, thiab ntsuas lub vijtsam kov.

Kauj Ruam 2: Qhov 2.8 "Kov Xim Zaub rau Arduino

Image
Image
Qhov 2.8
Qhov 2.8
Qhov 2.8
Qhov 2.8

Kuv pom lub vijtsam kov no ntawm banggood.com thiab txiav txim siab yuav nws txhawm rau sim siv nws hauv qee qhov ntawm kuv cov phiaj xwm. Raws li koj tuaj yeem pom cov zaub tsis kim, nws raug nqi ib ncig $ 11.

Tau nws ntawm no ▶

Cov zaub muaj kev daws teeb meem ntawm 320x240 pixels thiab nws los ua ib daim ntaub thaiv uas ua rau kev sib txuas nrog Arduino yooj yim heev. Raws li koj tuaj yeem pom, cov zaub siv yuav luag tag nrho cov digital thiab analog pins ntawm Arduino Uno. Thaum siv daim ntaub thaiv no peb tshuav nrog tsuas yog 2 tus pin thiab 1 tus pin analog rau peb cov phiaj xwm. Hmoov zoo, cov zaub ua haujlwm tau zoo nrog Arduino Mega ib yam nkaus, yog li peb thaum peb xav tau tus pin ntau dua peb tuaj yeem siv Arduino Mega hloov chaw ntawm Arduino Uno. Hmoov tsis zoo cov zaub no tsis ua haujlwm nrog Arduino Due lossis Wemos D1 ESP8266 board. Lwm qhov zoo ntawm daim ntaub thaiv yog tias nws muab lub micro SD qhov uas yog qhov yooj yim heev rau siv.

Kauj Ruam 3: Tsim Txoj Haujlwm thiab Xeem Nws

Tsim Txoj Haujlwm thiab Xeem Nws
Tsim Txoj Haujlwm thiab Xeem Nws
Tsim Txoj Haujlwm thiab Xeem Nws
Tsim Txoj Haujlwm thiab Xeem Nws
Tsim Txoj Haujlwm thiab Xeem Nws
Tsim Txoj Haujlwm thiab Xeem Nws

Tom qab txuas lub vijtsam mus rau Arduino Uno, peb tuaj yeem thauj cov cai thiab peb npaj ua si.

Thaum xub thawj, peb nias lub pob "Start Game" thiab qhov kev ua si pib. Arduino ua si ua ntej. Peb tuaj yeem ua si peb qhov txav yooj yim los ntawm kov lub vijtsam. Arduino tom qab ntawd ua nws qhov kev txav mus thiab lwm yam. Tus neeg ua si uas ua tiav hauv kev tso peb ntawm lawv cov cim hauv kab rov tav, ntsug, lossis kab pheeb ces kaum yeej qhov kev ua si. Thaum qhov kev ua si dhau lawm, Game Over screen tshwm. Peb tuaj yeem nias lub pob ua si dua kom pib qhov kev ua si dua.

Arduino zoo heev ntawm qhov kev ua si no. Nws yuav yeej feem ntau ntawm cov kev ua si, lossis yog tias koj yog tus neeg uas ua tau zoo heev qhov kev ua si yuav xaus nrog kev kos. Kuv txhob txwm tsim qhov txheej txheem no kom ua qee qhov yuam kev txhawm rau muab txoj hauv kev rau tib neeg ua si los yeej. Los ntawm kev ntxiv ob kab ntxiv rau cov cai ntawm kev ua si, peb tuaj yeem ua rau Arduino tsis tuaj yeem plam qhov kev ua si. Tab sis yuav ua li cas 2 $ nti, Arduino CPU, tuav tib neeg lub hlwb? Puas yog txoj haujlwm peb tsim ntse tshaj tib neeg lub hlwb?

Kauj Ruam 4: Game Algorithm

Game Algorithm
Game Algorithm
Game Algorithm
Game Algorithm

Txhawm rau teb lo lus nug no, cia saib lub algorithm uas kuv tau siv.

Lub computer ib txwm ua si ua ntej. Qhov kev txiav txim siab ib leeg no, ua rau kev ua si yooj yim dua rau Arduino los yeej. Thawj qhov txav mus yog ib lub ces kaum. Qhov thib ob, txav mus rau Arduino kuj tseem yog lub kaum ntse ntse los ntawm qhov seem uas tsis muaj kev saib xyuas txog cov neeg siv txav mus txhua. Txij ntawm no mus, Arduino thawj qhov kev tshuaj xyuas yog tias tus neeg uas ua ntawv tuaj yeem yeej hauv kev txav mus tom ntej thiab thaiv qhov uas txav mus. Yog tias tus neeg ua si tsis tuaj yeem yeej hauv kev txav mus ib leeg, nws ua lub ces kaum txav yog tias nws muaj lossis tsis raug xaiv los ntawm qhov seem. Qhov ntawd yog nws, qhov txheej txheem yooj yim no tuaj yeem tuav tib neeg cov neeg ua si txhua lub sijhawm lossis ntawm qhov xwm txheej phem tshaj plaws qhov kev ua si yuav ua rau raug kos. Qhov no tsis yog qhov zoo tshaj plaws tic tac ntiv taw game algorithm, tab sis ib qho ntawm qhov yooj yim tshaj plaws.

Qhov txheej txheem no tuaj yeem ua tiav hauv Arduino yooj yim, vim Tic Tac Toe game yog qhov yooj yim heev, thiab peb tuaj yeem txheeb xyuas nws yooj yim thiab daws nws. Yog tias peb tsim cov ntoo game peb tuaj yeem tshawb pom qee cov tswv yim yeej thiab siv tau yooj yim hauv cov lej lossis peb tuaj yeem cia CPU suav cov ntoo game hauv lub sijhawm tiag tiag thiab xaiv qhov zoo tshaj plaws txav los ntawm nws tus kheej. Tau kawg, lub algorithm peb siv hauv qhov kev ua si no yooj yim heev, vim tias qhov kev ua si yog yooj yim heev. Yog tias peb sim tsim cov txheej txheem yeej rau chess, txawm tias peb siv lub khoos phis tawj nrawm tshaj plaws peb tsis tuaj yeem suav cov ntoo game hauv ib txhiab xyoo! Txog kev ua si zoo li no, peb xav tau lwm txoj hauv kev, peb xav tau qee qhov kev txawj ntse Artificial Intelligence algorithms thiab tau kawg ua lub zog loj. Xav paub ntau ntxiv txog qhov no hauv video yav tom ntej.

Kauj Ruam 5: Txoj Cai ntawm Txoj Haujlwm

Txoj Cai ntawm Txoj Haujlwm
Txoj Cai ntawm Txoj Haujlwm

Cia peb saib nrawm ntawm txoj cai ntawm qhov haujlwm. Peb xav tau peb lub tsev qiv ntawv nyob rau hauv kev txiav txim tus lej los ua ke.

  1. Adafruit TFTLCD:
  2. Adafruit GFX:
  3. Touchscreen:

Raws li koj tuaj yeem pom, txawm tias qhov kev ua si yooj yim zoo li no, xav tau ntau dua 600 kab ntawm cov cai. Cov cai yog qhov nyuaj, yog li kuv yuav tsis sim piav qhia hauv kev qhia luv. Kuv yuav qhia koj qhov kev siv ntawm cov txheej txheem rau Arduino txav mus.

Thaum xub thawj, peb ua ob lub ces kaum tsis raug.

<int firstMoves = {0, 2, 6, 8}; // yuav siv cov haujlwm no ua ntej rau (counter = 0; counter <4; counter ++) // Suav thawj qhov txav mus ua si {yog (board [firstMoves [counter]! = 0) // Thawj qhov kev txav yog ua los ntawm ib tus neeg {movesPlayed ++; }} ua {yog (txav <= 2) {int randomMove = random (4); int c = firstMoves [randomMove]; yog (board [c] == 0) {ncua (1000); board [c] = 2; Serial.print (firstMoves [randomMove]); Serial.println (); drawCpuMove (firstMoves [randomMove]); b = 1; }}

Tom ntej no, hauv txhua qhov kev sib tw peb xyuas seb tus neeg uas ua ntawv tuaj yeem yeej hauv qhov kev txav mus tom ntej.

int checkOpponent ()

{yog (board [0] == 1 && board [1] == 1 && board [2] == 0) rov 2; lwm yog (board [0] == 1 && board [1] == 0 && board [2] == 1) rov 1; lwm yog (board [1] == 1 && board [2] == 1 && board [0] == 0) rov 0; lwm yog (board [3] == 1 && board [4] == 1 && board [5] == 0) rov 5; lwm yog (board [4] == 1 && board [5] == 1 && board [3] == 0) rov 3; lwm yog (board [3] == 1 && board [4] == 0 && board [5] == 1) rov 4; lwm yog (board [1] == 0 && board [4] == 1 && board [7] == 1) return 1; lwm tus xa rov qab 100; }

Yog tias yog peb thaiv qhov txav ntawd, feem ntau. Peb tsis thaiv txhua qhov kev txav chaw txhawm rau muab txoj hauv kev rau tib neeg ua si los yeej. Koj tuaj yeem pom qhov txav uas tsis raug thaiv? Tom qab thaiv qhov txav chaw, peb ua ib lub ces kaum ntxiv, lossis txav mus los yam tsis raug cai. Koj tuaj yeem kawm txoj cai, thiab siv koj tus kheej qhov tsis sib xws yooj yim dua. Raws li ib txwm koj tuaj yeem pom cov cai ntawm txoj haujlwm txuas nrog ntawm cov lus qhia no.

NCO TSEG: Txij li thaum Banggood muab cov duab zoo ib yam nrog ob lub vijtsam sib txawv, yog tias cov cai saum toj no tsis ua haujlwm, hloov pauv qhov pib ua haujlwm rau hauv qab no:

void initDisplay ()

{tft.reset (); tft.begin (0x9341); tft.setRotation (3); }

Kauj Ruam 6: Kev Xav Thaum Kawg thiab Kev Txhim Kho

Kev Xav Thaum Kawg thiab Kev Txhim Kho
Kev Xav Thaum Kawg thiab Kev Txhim Kho

Raws li koj tuaj yeem pom, txawm tias muaj Arduino Uno, peb tuaj yeem tsim qhov txheej txheem tsis txaus ntseeg rau kev ua si yooj yim. Txoj haujlwm no zoo heev, vim nws yooj yim los tsim, thiab tib lub sijhawm qhia zoo rau Artificial txawj ntse thiab kev ua si game. Kuv yuav sim tsim qee qhov haujlwm siab dua nrog Artificial Intelligence yav tom ntej siv Raspberry Pi muaj zog dua yog li nyob twj ywm! Kuv yuav nyiam hnov koj lub tswv yim hais txog qhov haujlwm no.

Thov tshaj tawm koj cov lus hauv qab no thiab tsis txhob hnov qab nyiam cov lus qhia yog tias koj pom nthuav. Ua tsaug!

Pom zoo: