Visual Basic Help!

  • Hey - turns out IRC is out and something a little more modern has taken it's place... A little thing called Discord!

    Join our community @ https://discord.gg/JuaSzXBZrk for a pick-up game, or just to rekindle with fellow community members.

Riv

TonTon
Oct 5, 2001
3,565
63
London
Hello Peoples!

Im doing my first bit of programming for my degree and I was asked to make Noughts and Crosses (Tic Tac Toe) in Visual Basic. Ive made the game, however, i need to add some computer AI to the game, but i have no clue at all on how I can do this. People have given me examples of how to do it and the steps I have to take but to be honest I dont know how/where to start and what code I have to use to implement it, so im just sitting here confused.. like normal!

Ive attached a .zip file of my whole project and also a .txt file of just the code.

Thanks
 

Attachments

  • code.txt
    6.9 KB · Views: 42
  • Noughts And Crosses.zip
    110.6 KB · Views: 33
Last edited:
hi mate. i am not drunk at all.

anyhoo, hire sumbody or learn the fuck out of it, head over to a freelancer site like getafreelancer.com (dno if they got VB) to get sumbody cheap to help you...

hope this helps you somehow.. the examples i showed u already (hi g00gle).

keep the code to urself, nobody here is gonna help you unless you pay them at least 30 per hour, and indians work for a whole lot less than that lol
 
Try this:

10 IF opponent=Riv THEN gamestatus=win
20 GOTO 10

Or is that BASIC? I dunno, ask Daisuke like I suggested :fish:
 
in your txt-code you got alrdy a link to a sub/function called compAi. Just add such a function and program the code.
i doubt some1 here will write you an AI for free, because this is quite a complex task.

Just a hint: When you use programming rules, using explicite prefixes for objects (e.g. calling Buttons btn_OK1, callin Functions F_CompAi, listes lst_Members, etc) the code is way easier to read.
Also consider using the with...end with command.
 
Last edited:
Well, wrote two lil functions
Not perfect and not mucho tested. But maybe it helps ya nevertheless.

Just copy the code under your normal functions subs and add a normals command button to the form, so you can test it.

Ofc this should be executed after the user clicked, but tbh i was too lazy to add that.

Oh and no idea how i can force Vb2008 to draw the X and O's on teh board (with the Symbol function it didnt work), so it only says "X in position 2,1).
Just search & replace it then with the functions to draw symbols.

Also i gave the PC the X-symbol. If you wanna do it configurabel, just replace the dummy-variable "X" with the function for selecting it.
 
Last edited:
What kind of AI do you have to add? "Some AI" sounds really... easy ;) Just write the code simulating a computer player which picks a random free position. Building AI which picks positions based on the amount of winning possibilities and / or draws will be a lot harder.
 
I've already given him pseudo code of the AI, which riv found difficult cos hes a bit of a spazz

I gave him the first 2 basic bits in a bit of detail:

If you can win, then win
If you can't win, then block
If there is no block then make a move - this could be random or an informed move.

since it's undergrad level i dunno if an informed move routine is required
 
Last edited:
not sure what kind of things they expect from you but since it's a very small turn-based deterministic game.... you can make a very basic (and un-optimized) Mini-Max algorithm, won't need any pruning and can always calculate to max depth (end of the game)

GL