Thread: chess playing Robot

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    2

    chess playing Robot

    hello guys i need your help. I am making a robot which can plan chess but i am stucked with programming i need a C++ code which can control to robot. To make control easier , code should give 4 number. Two of them are coordinate which robot wants to play for example (a1 -pawn ) the others are which robot will play.
    thanks

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Writing code to control a robot, and writing code to intelligently play chess, are two completely separate disciplines.

    Are you talking about writing code for a robot that actually moves physical chess pieces on a board?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by chess06 View Post
    i need a C++ code which can control to robot.
    And I need a million dollars. Neither of us is going to get what we "need" by asking for it on this forum.

    Start by researching robotics on google. There's lots of people using Arduinos to control all kinds of robots. I'm sure you can find something that will get you started.

    You need to do your own work, and ask for help when you get stuck. Getting "stuck" on starting your program doesn't count. You're likely to get answers like:

    Code:
    int main()
    {
      return 0;
    }
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    Do you want the robot to be intelligent? or just play the game randomly?

  5. #5
    Registered User
    Join Date
    Mar 2015
    Posts
    2
    first sorry for bad english, i am using english as a second language so there can be some mistakes. second it can play randomly. problem is actually how can i make robot to understand what it needs to do. We made a chess game in c++ but i am not sure how i can use them to control to robot

  6. #6
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    Well it sounds like you're set on a design of a "robot." If you want to model a robot create a class called Robot (because this is c++). The robot doesn't need to understand what it needs to do.

    Now in this robot class you can pick a random chess on the board and locate all the places in can move based on the rules it must follow. Then it should randomly pick from the possible open moves.

    As long as you don't need AI then it should be pretty simple. Just use random numbers.

  7. #7
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    If you have a Grid class that can represent the board, you could make a class for each of the pieces. The class for the pieces could contain an array of vectors representing possible moves. Then you could make a method for the pieces class, called "look", that takes the grid as an argument. The "look" method would then construct an array of possible moves, based on information from the passed Grid and it's own moves.

    In short pseudo-code what I'm thinking of is something like this:

    Code:
    // Where "this.moves" is an array of Vector representing possible moves
    // The grid methods "isEnemy" or "isEmpty" take Vector for argument, 
    // and return boolean value specifying what is at that space.
    
    // You could also define a more general "Grid::get()" method that 
    // returns an enum value specifying type.
    
    Vector Horse::act (Grid grid)
    {
        Vector move = chooseRandomElement(this.look(grid));
        return move;
    }
    
    std::vector<Vector> Horse::look (Grid grid)
    {
        std::vector<Vector> result;
    
        for(int i = 0; i < this.moves.size(); i++)
        {
            if (grid.isEnemy(this.moves[i])
            {
                result.push(this.moves[i]);
                break;
            }
            else if (grid.isEmpty(this.moves[i]))
            {
                result.push(this.moves[i]);
            }
        }
        return result;
    }
    This code has a few problems, for one a static list of possible moves is not appropriate for every piece. The queen for instance can move in 8 directions, for the length of all valid squares. It might be better to instead create a method that constructs a list of moves dynamically, based on the pieces current position, then uses the "look" method to whittle down the possible list of moves.

    Edit: The reason why I like this method, is that all pieces are generally the same. Every piece could theoretically derive from a base class that contains the "act" and "look" methods. So that the data structure representing the board could contain all types of pieces.
    Last edited by Alpo; 03-16-2015 at 12:05 PM.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. robot code
    By pureflip428 in forum C Programming
    Replies: 2
    Last Post: 12-03-2012, 08:28 PM
  2. programming a robot
    By sauoon in forum C++ Programming
    Replies: 1
    Last Post: 02-26-2010, 08:39 AM
  3. Help! Robot Programming
    By Gizzle in forum C Programming
    Replies: 23
    Last Post: 09-28-2006, 07:32 AM
  4. I, Robot -- It's a trick, and I'm mad.
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-15-2004, 01:57 PM
  5. Robot programming
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 06-05-2002, 11:29 AM

Tags for this Thread