Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,755 members, 7,820,618 topics. Date: Tuesday, 07 May 2024 at 06:20 PM

Tic Tac Toe Online Game With AI - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Tic Tac Toe Online Game With AI (4692 Views)

A Simple Tic-tac-toe Game Using Javafx / Html/css/javascript Tic-tac-toe Project / Advanced Tic Tac Toe Online Game (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: Tic Tac Toe Online Game With AI by FincoApps(m): 5:13am On Aug 17, 2015
hmmmmmm, niceeee, this looks like it would work but for example, if I Win in like a double way, the endGame method would be called twice. I'll use this method when I want to improve the AI, because the AI part is so bulky, that I usually copy the portion of code I want to edit out to a different IDE.

jacob05:
Can't sleep, undecided, so i decide to view your code... (was afraid before..lol... make person head no come turn...)

I observe you repeat similar try .... catch blocks which greatly increase the size of your code (bad) and causes a lot of duplication...

so I'd like to suggest this.. (Not Tested.... but should be of help.... i guess wink )


CheckWon

function checkWon(who,xy, a1,a2){
var values = new Array(5);
values[0] = table[xy[0]][xy[1]];
values[1] = table[xy[0]+ a1[0]][xy[1] + a2[0]];
values[2] = table[xy[0]+ a1[1]][xy[1] + a2[1]];
values[3] = table[xy[0]+ a1[2]][xy[1] + a2[2]];
values[4] = table[xy[0]+ a1[3]][xy[1] + a2[3]];
console.log(values);
if (document.getElementById(values[0]).getAttribute('played') == who &&
document.getElementById(values[1]).getAttribute('played') == who &&
document.getElementById(values[2]).getAttribute('played') == who &&
document.getElementById(values[3]).getAttribute('played') == who &&
document.getElementById(values[4]).getAttribute('played') == who)//AI has an horizontal winning move
{
for(var x= 0; x < values.length; x++)
{
$('#'+values[x]).css('background', 'url(img/tile' + who + 'W.png)');
$('#'+values[x]).css('background-size', '100%,100%');
$('#'+values[x]).css('background-size', 'cover');
}
endGame(who);
return;
}

}


Usage

try {
//------Check tiles diagonally rightways-------

checkWon(who,getXY(tileID), [1,2,3,4],[1,2,3,4]);
} catch (e) {
}

try {
//------Check tiles vertically-------

checkWon(who,getXY(tileID), [1,2,3,4],[0,0,0,0]);
} catch (e) {
}

try {
//------Check tiles horizontally-------

checkWon(who,getXY(tileID), [0,0,0,0],[1,2,3,4]);
} catch (e) {
}

try {
//------Check tiles diagonally leftways-------

checkWon(who,getXY(tileID), [1,2,3,4],[-1,-2,-3,-4]);
} catch (e) {
}




This Can also be tweaked to work for other functions like checkWinningMoveAI and the rest...
Re: Tic Tac Toe Online Game With AI by FincoApps(m): 5:14am On Aug 17, 2015
You guys should try playing online,and let me know how it is grin
Re: Tic Tac Toe Online Game With AI by thewebcraft(m): 9:11am On Aug 17, 2015
Was not what I expected but nice one bro.
Re: Tic Tac Toe Online Game With AI by FincoApps(m): 10:15am On Aug 17, 2015
Thanks smiley. What did you expect shocked
thewebcraft:
Was not what I expected but nice one bro.
Re: Tic Tac Toe Online Game With AI by Nobody: 10:34am On Aug 17, 2015
FincoApps:
Thanks smiley. What did you expect shocked
I wonder o. BTW, them don ban me for trolling again o (as usual).
Re: Tic Tac Toe Online Game With AI by FincoApps(m): 10:42am On Aug 17, 2015
hahahaha, pele grin
donjayzi:

I wonder o. BTW, them don ban me for trolling again o (as usual).
Re: Tic Tac Toe Online Game With AI by Nobody: 10:58am On Aug 17, 2015
FincoApps:
hahahaha, pele grin
I think i need to start begging o!
Re: Tic Tac Toe Online Game With AI by jacob05(m): 5:38pm On Aug 19, 2015
dhtml18:
^^^joblessness at its peak!

Haaaaa Haaaa... When bosses no give work nko?
Re: Tic Tac Toe Online Game With AI by Nobody: 10:57am On Jan 23, 2016
I remember this project!
Re: Tic Tac Toe Online Game With AI by FincoApps(m): 9:05am On Jan 24, 2016
dhtml18:
I remember this project!

lol, I'll soon go back to it though. I wanna work on the AI and use that Algorithm I told you about
Re: Tic Tac Toe Online Game With AI by Nobody: 9:53am On Jan 24, 2016
Okay, is alright, I might be able to help you out when you are ready. My programming skills have stepped up considerably since last time we worked on that stuff.
Had to work on some badass stuffs of recent, and that forced me to upgrade. As an aside, I can now even make browser plugins for chrome and mozilla.

1 Like

Re: Tic Tac Toe Online Game With AI by FincoApps(m): 3:40pm On Jan 24, 2016
dhtml18:
Okay, is alright, I might be able to help you out when you are ready. My programming skills have stepped up considerably since last time we worked on that stuff.
Had to work on some badass stuffs of recent, and that forced me to upgrade. As an aside, I can now even make browser plugins for chrome and mozilla.

hmmm yea I would really love it if you can contribute to it. And I wonder the project that made you start learning about browser plugins cheesy. Also, can you give me your contact
Re: Tic Tac Toe Online Game With AI by Nobody: 4:46pm On Jan 24, 2016

2 Likes

Re: Tic Tac Toe Online Game With AI by FincoApps(m): 7:48pm On Jan 24, 2016
dhtml18:
just a regular project - call it self-exploration - https://chrome.google.com/webstore/detail/dhtmlconsole/jojehgiefnbpeljgiofpdmmdeklckbdd

lol so u are really serious. It's mainly for web developers right
Re: Tic Tac Toe Online Game With AI by Nobody: 9:01pm On Jan 24, 2016
Yeah, that way you can debug ajax apps very easily with your browser.
Re: Tic Tac Toe Online Game With AI by sinequanon: 11:44pm On Jan 24, 2016
FincoApps:


lol, I'll soon go back to it though. I wanna work on the AI and use that Algorithm I told you about

It's almost human already! I got five in a row and it just decided to sulk and carry on without conceding.

Then, when I got seven in a row, it silently took a coffee break, and never returned!

That's smart!

AI FTW!
Re: Tic Tac Toe Online Game With AI by Nobody: 12:45am On Jan 25, 2016
This one ain't tic tac toe again!

Re: Tic Tac Toe Online Game With AI by Nobody: 5:35am On Jan 25, 2016
sinequanon:


It's almost human already! I got five in a row and it just decided to sulk and carry on without conceding.

Then, when I got seven in a row, it silently took a coffee break, and never returned!

That's smart!

AI FTW!
lol
Re: Tic Tac Toe Online Game With AI by DanielTheGreek(m): 5:36am On Jan 25, 2016
DanielTheGeek:
This one ain't tic tac toe again!
Very funny!

1 Like

Re: Tic Tac Toe Online Game With AI by Nobody: 6:44am On Jan 25, 2016
DanielTheGreek:

Very funny!


Hmmm, Duplicate account..Who are you?
Re: Tic Tac Toe Online Game With AI by Nobody: 7:01am On Jan 25, 2016
DanielTheGeek:



Hmmm, Duplicate account..Who are you?

Programmatically speaking,
DanielTheGeek != DanielTheGreek

They might be similar but certainly not duplicate.
Re: Tic Tac Toe Online Game With AI by FincoApps(m): 8:43am On Jan 25, 2016
I was testing something in the web version so Playing with computer won't work. Only online would work. If you still wish to test it, download from here:

For Android: https://play.google.com/store/apps/details?id=com.fincoapps.tictactoe&hl=en
For BlackBerry: https://appworld.blackberry.com/webstore/content/59970958/?lang=en&countrycode=NG
Re: Tic Tac Toe Online Game With AI by Nmeri17: 11:00am On Jan 25, 2016
DanielTheGeek:



Hmmm, Who are you?
idk why I find this so funny grin grin grin

Imagine. At first I was wondering why you quoted yourself with that "very funny" till I took a closer look.

Modified
I just checked your profiles.
function DeactivateUser (profile) {
delete Nairaland.profile;
}

DeactivateUser(danielTheGreek); angry
Re: Tic Tac Toe Online Game With AI by sinequanon: 11:56am On Jan 25, 2016
FincoApps:
I was testing something in the web version so Playing with computer won't work.

It's OK. It's fixed itself now, using its Artificial Intelligence.

People must have been cheating against it, because it has learned how to cheat.

It keeps pretending not to notice when you win, and it makes extra moves when it thinks you're not looking.

As for the game against DanielTheGeek, maybe it had an off day, or had just had a spliff.

(1) (2) (Reply)

Rynga Voip Issues - The Call Failed Due To Sound Device Problem On This Computer / My New Start Up, Life As A Programmer And Testimony. / Simple Server

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.