Author Topic: Java final project!  (Read 5529 times)

0 Members and 1 Guest are viewing this topic.

Offline Darkness

  • x86
  • Full Member
  • ***
  • Posts: 234
    • View Profile
Java final project!
« on: December 04, 2005, 03:59:16 pm »
For intro to cs I'm thinking of making a graphical chess game for our final project (we're free to make any game). I'm trying to think of ways to make a good AI computor. Any ideas on how to program it? I'm not looking for any code, I just want ideas. Getting code would be cheating =/
(01:22:35) Newby: I am listening to 9989. Torsofuck - Fistfucking Her Decomposed Cadaver (0:07 / 2:37 320kbps)
(01:22:39) Newby: I am listening to 9990. Torsofuck - Worm Infested Anal (0:01 / 3:02 320kbps)
(01:22:43) Newby: I am listening to 9991. Torsofuck - Raped By Elephants (0:02 / 4:14 320kbps)

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Java final project!
« Reply #1 on: December 04, 2005, 04:08:29 pm »
For intro to cs I'm thinking of making a graphical chess game for our final project (we're free to make any game). I'm trying to think of ways to make a good AI computor. Any ideas on how to program it? I'm not looking for any code, I just want ideas. Getting code would be cheating =/

I don't think it would be very wise to attempt a chess AI.  I don't think anyone without a few years of statistics/calculus/other math classes could even start to imagine how a chess AI should function.  I suppose you could make one, but it would probably suck.  :)

Just make it two player.

On a side note, if I HAD to create an AI, I'd do something like this:

Make a class for each chess piece.  When it's the computer's turn, it should analyze everything with in a 10x10 distance (or whatever is appropriate) and rate pieces in its range at some "danger" level.  It'd loop through each existing piece and then calculate an appropriate action.

I suck at chess, so I'd suck at making the ratings, etc.  I'd read a book on chess before I did this also.
« Last Edit: December 04, 2005, 04:11:03 pm by Sidoh »

Offline Darkness

  • x86
  • Full Member
  • ***
  • Posts: 234
    • View Profile
Re: Java final project!
« Reply #2 on: December 04, 2005, 05:40:15 pm »
I do have to have an AI, but it just has to be decent. That's a good strategy, but I guess I could go further with that for different difficulty levels, like higher order thinking. Like if difficulty is one then I could do that, then if difficulty is two I could do that and then check what moves the player could make. Thx for the idea.
(01:22:35) Newby: I am listening to 9989. Torsofuck - Fistfucking Her Decomposed Cadaver (0:07 / 2:37 320kbps)
(01:22:39) Newby: I am listening to 9990. Torsofuck - Worm Infested Anal (0:01 / 3:02 320kbps)
(01:22:43) Newby: I am listening to 9991. Torsofuck - Raped By Elephants (0:02 / 4:14 320kbps)

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Java final project!
« Reply #3 on: December 04, 2005, 05:52:15 pm »
I do have to have an AI, but it just has to be decent. That's a good strategy, but I guess I could go further with that for different difficulty levels, like higher order thinking. Like if difficulty is one then I could do that, then if difficulty is two I could do that and then check what moves the player could make. Thx for the idea.

Oh, well that kind of sucks...

Yeah, that's one way of doing it I suppose.  Also, assuming you could construct an extremely intelligent AI (Which would take a shitload of study in Chess and statistics), you could rank the possible moves.  Different difficulty levels rolls a random number.  If it's between a certain range, it selects its best move; if not, it moves its second, third, etc best move.

Offline Blaze

  • x86
  • Hero Member
  • *****
  • Posts: 7136
  • Canadian
    • View Profile
    • Maide
Re: Java final project!
« Reply #4 on: December 04, 2005, 07:15:22 pm »
Real chess AI's plan for twelve moves ahead. :)
And like a fool I believed myself, and thought I was somebody else...

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Java final project!
« Reply #5 on: December 04, 2005, 08:19:14 pm »
Real chess AI's plan for twelve moves ahead. :)

Like I said, you'd have to have a lot of background in statistics (possibly calculus, too) and chess in order to make a good AI.

You should do checkers instead, that would probably be a lot easier.

Offline zorm

  • Hero Member
  • *****
  • Posts: 591
    • View Profile
    • Zorm's Page
Re: Java final project!
« Reply #6 on: December 04, 2005, 09:23:59 pm »
Depending on exactly how complex the AI needs to be it should be rather easy to do. If you just need a basic AI that you can play against I'd suggest this:

Have 4 states:
Advancing
Attacking
Retreating
Sacrifice

Advancing:
This would be the state at the start of the game, you could decide on a simple goal like to get the pawns to the other side of the board. Basically you just need a strategy for how you want to move when pieces aren't at stake.

Attacking:
This would be when you can take an opponents piece. You can setup basic rules for this like "If I take this piece will the piece I take it with be taken?" If the answer is yes then you compare the values of the pieces. If the piece you are using is worth less than the piece you can take then take it. Overwise look for a better move. If the answer is no then you take it no matter the value of the pieces.

Retreating:
This would be when the opponent can take a valuable piece on their next move if you don't move something. Likely this should only be on the King+Queen; however, you could attach it to a random piece that isn't the pawn to make the game more interesting.

Sacrificing:
This would be when the King is in check and it has to be not in check at the end of the turn no matter the cost.

To make a more advanced AI you could just expand on these ideas. Say for example advancing, you could have an internal list of good setups for defense and have the AI try to move its pieces to form said defensive position.

If you do something like this you avoid the complex task of trying to have an all knowning AI that needs advanced formulas and such. A few basic rules and you are good to go.
"Frustra fit per plura quod potest fieri per pauciora"
- William of Ockham