Chess game programming

I have to create a text-based chess game between uppercase and lowercase letters against each other using a two-dimensional arrays.
1. I have to create the board and initialize the position of the letters.
2. I have to give the output of the initial state of the game, showing the board and the first positions of the letters.
3. I have to create the moves.(Meaning that i have to create an input to perform the entering moves)
And i have to make sure that with every bad input the program will to repeat the input....
If anybody of you have programmed a chess game like this before, i would appreciate any kind of help....
Edited by: 812599 on Nov 17, 2010 8:26 AM

mario.beka wrote:
meacod wrote:
812599 wrote:
I have to create a text-based chess game between uppercase and lowercase letters against each other using a two-dimensional arrays.
1. I have to create the board and initialize the position of the checkers.Just to give you a nudge - are you familiar with chess? What's the size of the board? How might that affect the structure you store your 'pieces' in? How will you represent pawns as opposed to kings, queens, rooks, and so forth?
Scratch out some ideas on paper,
Turn that into some pseudocode,
Write some Java,
Then come back to us if you have a specific question.Yeah that's the problem, cuz i have never played chess in my life....I'm just reading around now for the rules and movements of this game...in that case, don't bother.
A decent chess program requires in-depth knowledge of the game, knowledge only gained through years of playing it at competition level.
I've a small library of books about chess, have played it for going on 30 years, plus 15 years experience using Java professionally, and I'd not consider writing a chess playing program in Java as something I'd undertake on my own (and yes, I've studied the possibility of writing just that in a variety of languages I know about over the years, and even made a start a few times only to abandon it when the project became too big for me to handle).
If you're only looking to make a digital chessboard, that's a much simpler task and one that you can certainly attempt even without knowing the game (except maybe the starting positions and accepted icons for the pieces and the size and nomenclature for the board and its fields).
Start with that, then add rules validation as players move pieces. Start with large rules (like enforcing that pieces can only move legally, in itself a somewhat daunting task as there are several pitfalls and special rules depending on piece positions).
At this stage there's still no AI, no computer player option. That's where the real work sits, and it's very much a non-trivial task.

Similar Messages

  • Programming a Chess-game - Design Tips

    Hello,
    I'm definatly not new to programming, but I'm a beginner at Java. Now I'm trying to program a little chess-game, which should teach me some OOP-techniques and to get some experience with Java.
    Well, I have some ideas for the game in mind and already realized a few things, but I want to do it the right way and get some advice from you.
    - The chess board:
    Currently, I have a class handling the drawing of the board, getting the screen-coordinates, etc.. The class "GameBoard" extends a JPanel and I overwrite the "paintComponent"-method to draw the board.
    I have a second class "Field" that stores informations of one field: What color the field is, which piece is placed on this field and which player "owns" it. Also, each one of these "Field" is getting passed its coordinates on the screen from "GameBoard". This helps me later, when I want to decide, if the field is clicked or not.
    Now, is this a good way to implement the board and the fields? I have another option, which would be, that I throw out the class "GameBoard" and instead have a "FieldHandler" class. Now, the class "Field" would extend JPanel, overwrite "paintComponent" and draw a square on the screen. "FieldHandler" gives each "Field" the information, if it should be black or white. "FieldHandler" would also calculate the x- and y-coordinates for each field.
    Is this method better? I don't really know performance wise, because I have to add 64 JPanels to the contentPane, which means, that all 64 Panels need to be drawn seperately. I don't know if this is a good way, but maybe it doesn't really matter. One advantage would be, that I could change the color of a field easily, for example when I click or hover it, which is not that nercassary, but still nice.
    Maybe there is an even better way?
    - The Pieces:
    Well, I don't really have a clue how to draw the pieces on the board. I could also make them extend JPanel and then draw the image onto some coordinates. But that doesn't seem too right. What about BufferedImage? I don't really know how to use it, neither when it is appropriate to use. I think I get more advantage of this, when I have animations, but that's definatly not my intention.
    The only thing I know is, that I can show an image on the screen with:
    ImageIcon test = new ImageIcon("Test.gif");
            public void paintComponents(Graphics g) {
                test.paintIcon(this, g, 100, 100);
            }But is this right or even way to do it? I'm somehow unsure, if an "ImageIcon" is right for a chess-piece. Any other ways of doing this?
    The "Piece"-class itself is just an interface that the classes "Knight", "King", etc. extend. It draws the piece onto the screen, set the owning player, sets the coordinates of a piece (with the help of the "Field"-class; The Field doesn't know it's exact coordinates, just "A7", "E3", etc.) and some other functions. All pieces are handled by a "PieceHandler", which could provide functions for counting all pieces on the field, initialising every piece and maybe some more things.
    Anybody got some advice on this approach?
    This should be enough for now. I would be very thankful for any kind help, I really want my first project to be as good as possible, since I want to learn OOP and Java better.

    - The chess board:
    Currently, I have a class handling the drawing of the
    board, getting the screen-coordinates, etc.. The
    class "GameBoard" extends a JPanel and I overwrite
    the "paintComponent"-method to draw the board.
    I have a second class "Field" that stores
    informations of one field: What color the field is,
    which piece is placed on this field and which player
    "owns" it. Also, each one of these "Field" is getting
    passed its coordinates on the screen from
    "GameBoard". This helps me later, when I want to
    decide, if the field is clicked or not.
    Now, is this a good way to implement the board and
    the fields? I have another option, which would be,
    that I throw out the class "GameBoard" and instead
    have a "FieldHandler" class. Now, the class "Field"
    would extend JPanel, overwrite "paintComponent" and
    draw a square on the screen. "FieldHandler" gives
    each "Field" the information, if it should be black
    or white. "FieldHandler" would also calculate the x-
    and y-coordinates for each field.
    Is this method better? I don't really knowWhat I'd do: just paint a chessboard pattern from a static image. Can be loaded from a file, or can be generated once dynamically. Don't care at all about fields.
    Have some pixel-to-field coordinate mapping somewhere. Should be nothing but a simple multiplication.
    Have a List of chess pieces. Have those know what they look like (maybe using a delegate object which contains an image), have those know where they are and where they can go. When painting, iterate over the list, transform the coordinates to pixels, get the UI delegate and paint its image. Why bother calculating 64 fields if all you have are 32 pieces or less? And whether a field is black or white doesn't matter to the game.
    When the user clicks onto the board, get the coordinates of the click and transform them to the field coordinates, that you can then look up in the list of figures. If you find one, you can still paint a marker onto the board and underneath the piece image.
    This is what I'd do. Other approaches might make sense as well..

  • How to create chess game using Adobe flash CS3

    I want to develop a web application that when a user is login the game will automatically search for oppents onlinethat are accessing the same website. I want to design a chess game that does not contain any AI programming. What I want is that a simple chess setup that online user can only play.

    use google to search for tutorials.  that's a very complex undetaking so unless you feel you have advanced programming skills, you would be better served starting with a simpler game like tic-tac-toe.

  • Help in a chess game

    hi can anyone help me? i would like to create a simple chess game for only two players.

    hi can anyone help me? i would like to create a
    simple chess game for only two players.in contrast to a simple chess program for more than 2 players?
    A chess program for 2 players is rather simple, it only needs an engine to determine whether a proposed move is legal or not.
    The tricky part is adding a computer player.

  • Multiplayer game programming - Code of a basic server

    I'm a beginner in multiplayer game programming and I'm looking for the code of a basic server for a multiplayer game. I don't mind which kind of game (I mean: chess, ping-pong, battlenet...) The important thing is the code pattern abnd the server structure.
    Could anyone help me?

    If you want to have a look at a generic multi-threaded server, check out the Java networking tutorial.. there's a basic example server that responds to a "Knock knock, who's there?" conversation.. you can start off with it..
    Of course it's not a game server but you could try sticking in a game engine to maintain the game world and change the user sessions to a proper game protocol.. e.g. sending key strokes or joystick movements. You could also get the server to send player and enemy positions etc...
    Good luck!

  • Use j2me to develop a chinese chess game

    Hi, i am new to J2ME but i have some experience on J2SE.
    Until now i still have no idea how to develop a j2me system. i already install j2me tool kit but dunno how to use and also installed Forte. The forte is just like a java builder and i now is working on it.
    Can anyone help me with this programming? I have a project to do and the project title is Developing a Chinese Chess Game in PDA using J2ME.
    Pls help me and give me some references or some sample coding of j2me.

    Alot of stuff online. Here's some to get you started:
    wireless toolkit tutorial -
    http://developers.sun.com/techtopics/mobility/midp/articles/wtoolkit/
    sample codes and articles-
    http://developers.sun.com/techtopics/mobility/allsamples/
    http://developers.sun.com/techtopics/mobility/allarticles/
    http://developers.sun.com/techtopics/mobility/allttips/
    Hope this helps. Good Luck.

  • Chess Game Help

    OK, I'm creating a chess game where you play against the computer. I have a good idea of how I am going to program the AI, but I need some basic stuff. Is there any code out there that has everything in it except the AI? Or at least some that draws the pieces and lets you move them around so I can work off of them? Thanks for your help.

    Thank you very much Alex. That's exactly what I
    need! I didn't think to search for AI in Google. :-P
    I'll be sure to take a look at that tutorial!Geez, I don't know why that wasn't obvious? After all I would typically search for AI when asked for:
    [url #" style="font-size: 18; color:navy;]Is there any code out there that has everything in it except the AI?
    Yeah, that makes sense!

  • I recently downloaded a 10.6.8 update and a game program has now been reduced in size.  It's specifications are set for full screen, but it is about 1/4 of the size.  Any ideas how to fix?

    I recently downloaded a 10.6.8 update and a game program has now been reduced in size.  It's specifications are set for full screen, but it is about 1/4 of the size.  Any ideas how to fix?

    Hi, I have got the same problem but all is 1/4 the size have you fixed it?

  • Chess game in Mac OS X is there a bug fix for it

    This is not a major issue but I have noticed it on all the Apple computers I have played the Chess game that comes with the Mac OS X and it seems to only involve the Pawn making an illegal move when capturing another piece. As we all know the Pawn can only capture by one space in a diagol move yet the Mac OS X supplied Chess game a Pawn will and can often capture an opponents piece that is directly next to it, yet still moves in diagnol fashion and for the same token this illegal move can is sometimes offered to me if I ask for a move hint. This is very frustrating as I play the supplied chess game often is there a fix for this bug

    Hello again Daniel...
    I found a thread where "cornelius" suggested corrupt preferences as a potential cause for Chess problems...
    His solution was to go to your Home > Library > Preferences and drag your com.apple.Chess.plist to the DeskTop and Restart your computer and reopen the Chess game...see the link
    http://discussions.apple.com/thread.jspa?messageID=2758136?
    Good Luck dave
    iMac G5 17/1.8/FirstGen/1GB RAM Mac OS X (10.3.9) Seagate200GB/WD160GB/iSight/Shuffle/SecGen Nano2GB
    iMac G5 17/1.8/FirstGen/1GB RAM   Mac OS X (10.3.9)   Seagate200GB/WD160GB/iSight/Shuffle/SecGen Nano2GB

  • Applet Game Programming - player movement

    HI Java Experts,
    I have a very simple question applet game programming - jdk 1.02.
    Let's say you have a player on the applet window. He can move right and left.
    Naturally you have an image representing the player. When the player moves left you present an image loop with him running left. And vice versa for running right.
    Of course when he stops moving you just want to show a still image.
    What do you guys feel is the best technique for that situation ?
    Stephen

    Hi Thanks for the advice.
    I'm under the impression that if I used jdk1.4
    everybody who wanted to play the game would have to go
    through the trouble of downloading something . If
    that is so, then i would like to stick with 1.02 to
    have the widest possible audience.Use Java Web Start to deploy it as an application instead of an Applet. If your program is really cool, people will download the JDK 1.4 to use it. Then we will have more java users in the world :)
    By the way i have a URL perhaps someone could look > at the source code and give additional suggestions
    you can make sonic the hedge hog run and jump
    http://www.swebdev.com/Adventure.html
    That code has some good points. I like the nice object oriented flow of it. However, the way he sets up the Thread is all wrong. He uses yield and sleep, you would want to set up this using wait() and notifyAll() calls if you want to make it more interesting.
    Right now i'm trying to address the issue of how to
    reverse the image for when the player is running the
    opposite way -- ? perhaps a separate thread in 1.02
    might be an answer? I would be glad to hear all kinds
    of suggestions on the sample code seen thereYou shouldn't need a separate thread just to reverse the image. If your little guy is already in his own thread, just switch the image that is displayed when the player hits the opposite direction key.
    Think of threads like puppets, and you are the puppet master. Your little guys is a puppet, so he should be in his own thread. You can make him do whatever you want from your thread (the master) by pulling strings (changing globals, and message passing)
    Wow... Thats a really good analogy... I just thought that up :)

  • Timer for game program.

    Hello all,
    I am making a game program and I need a way to implement a timer so that it the game will end if the time expires.
    Is there any easy function to help me with this task?

    Thanks for the reply and I just found that class.
    Thanks

  • J2ME game programming

    Helo everyone,
    I am working in j2me game programming plz if
    any one know how make image as small as possible
    in our game program.?
    I am using *.png format of image which is working well
    in game but my game size is very big so plz help me to get
    out of this problem
    Thank u
    Aman Gautam

    hi,
    if you want to do any kind of game programming in J2ME, i suppose you would require to use the Canvas class, well there are a few good resources.. try out
    www.billday.com
    www.javamobiles.com..
    that ought to get u started.
    cheerz
    ynkrish

  • J2Me game programming plz help

    Helo everyone,
    I am working in j2me game programming plz if
    any one know how make image as small as possible
    in our game program.?
    I am using *.png format of image which is working well
    in game but my game size is very big so plz help me to get
    out of this problem
    Thank u
    Aman Gautam

    I solved the same problem by using indexed color images instead of true color.
    So, for example, if you have a colorful background you can convert it to a 256 color image.
    Depending on your specific image and the devices you'll see it on you may or may not notice the difference, but the file size is generally smaller.
    Then you can push further for smaller elements, like, say, a moving object like a pointer or a starship, you can reduce it to 60 or 30 colors, or even less.
    Another technique is to use tiles to build up the background instead of big images. With MIDP2.0 there's the TiledLayer, but you can implement the same with some code also on MIDP1.0 if backward compatibility is of concern.

  • I want to learn 2D game programming. But, I am confused!

    I want to make a 2D game in C#. I have begun learning C# on my own. But, I am confused sbout what to learn after c# to make a game. I hear many things like XNA, MDX, Monogame, SlimDX, SharpDX, Frameworks, game engines, IDE's etc. To me all of this has
    caused a great confusion. The C# game tutorial I am learning is based on MDX (Managed DirectX). Now, I realise that MDX and XNA is dead. I am confused if I want to change my tutorial itself. Can anyone clear things out for me and tell what i need to learn
    step by step?
    I really don't even know what all the sh*t (.NET ,XNA, Monogame, SharpDX, xxx, xxxx, xxxx etc.) really is or what it does or which is better or even what the differences are. So please explain everything to me. Please help!

    Hi,
    You can refer to the Books:
    Beginning .NET Game Programming
    Beginning C# Game Programming
    Few other useful links:
    Coding 4 Fun is a great .NET resource that has quite a few user-created games. They also have a
    book and a
    2-D game primer
    Tutorial Listing at C# corner
    C# Game Tutorial for Beginners (video)
    Link to more game programming e-books
    Advanced Topics
    The Farseer Physics Engine on Codeplex would be a good next step once you get comfortable with programming games.
    Please mark as answer or vote as helpful if my reply does

  • About game programming.. please....help

    How to define game map for java midlet
         If I see the rpg game, it have default map. I want to know how to translate it to code
         in midlet? The map will be existed image or dynamicly generated?
         Like Prince of Persia Midlet version, I wonder how to generate the environment?
         Is it pixel generated or immutable image?
    detect collision
         SO if the map is image and the sprite game is draw over the map, how can we detect the
         collision?
         Please hellp me.... because I want to be game programmer for midlet but I
         didn't know about game programming before

    to write a small game in midl is already a hard work. to make a big one, take a look of a team of programers.
    about maping, there is no such thing. wire every thing by yourself. by books or read tutorials.
    as i already said. no easy task.
    but keep on trying. if you need some help write me a mail.
    [email protected]
    jeliel
    (sebastian)

Maybe you are looking for

  • Any suggestions for waterproofing?

    Hi. I'm on a long holiday and want an e-reader I can use in the pool, bath or at the beach. Was thinking about getting an Ipad2 and am wondering if anyone else has tried to waterproof an Ipad for reading around water? I'm not talking about submersing

  • Can anyone explain to me why my picture looks like this?

    Okay, I'm new to this forum so I hope I'm not breaking any rules by posting a link to another forum. The reason I'm doing this is so that I don't have to keep covering the same questions over and over again. In this previous forum I have already answ

  • My tabs bar and tabs have all turned HUGE and I don't know how to fix it?

    I have just opened the mozilla firefox 4 beta and all my tabs have turned really big. I've tried restarting my computer but it's still the same. Has anyone got any ideas on how to fix this problem without uninstalling firefox. Thanks. By the way, I w

  • FORGOT MASTER PASSWORD...  HELP!!

    I forgot my master password and want to reset it, how can i do that? I dont have firevault on and I know my account pass

  • Unwanted Table Creation In Database

    Hi This is Anandkumar From India Presently working as DBA right now we r running 10.2 g Oracle Database In RAC Environment On Windows 2003 R2 Standard Edition. Now the problem is that in database there are some unwanted tables created in the database