Tuesday, February 21, 2012

Next tutorial in the android series


Sorry, for the delay in the android tutorial series.  Trying to keep up with the daily grind, as well as, 22 credit hours this semester.  I will hopefully have up the next in the series if not the rest of the series by the end of the weekend.  If anyone has any ideas on what to do another tutorial or series on, please, leave a comment and I will see what I can do.  Currently, I am not sure if the next tutorial will be on android development or something else.  I just finished up an assignment dealing with android development and it was pretty interesting.  It had to deal with creating dialogs and the different types of dialogs that can be created.  You can view the app up on the market place and see if maybe you would be interested in something along these lines.

I am kind of holding off until I get actual free time to devote to a long series.  I was thinking about maybe doing a series on developing a game in C# using XNA, but I would not want to start on it and then have a big gap in the series.  So, until then I may just continue with smaller projects or some general tutorials.  Anyways, I look forward to any suggestions that you all might have.


Check us out on Google+ (Indie Development).
Check us out on our .co site (Indie Development).

2 comments:

  1. Hey Man i have followed your code very nicely done an excellent rescouse but i hope you wont mind if i could refine your getcomputermove() method a little you dont need to do that lengthy logic and check the winners in that code because you are already doing that in your tic tac toe activity class so your getcomputermove() method could be a lot simple like this n this works like a charm since we r just intrested in getting the computer move we can set the move later on in the activity

    public int getComputerMove()

    {
    int move = 0;

    for(int i =0; i < this.GameBoard.length; i++)

    {
    if(GameBoard[i] != Computer && GameBoard[i] != Player)

    {

    do
    {
    move = random.nextInt(BoardSize);

    }while(GameBoard[move]== Computer || GameBoard[move] == Player);

    }

    }

    return move;


    }

    ReplyDelete
    Replies
    1. This will work to generate a random move, but it will take out needed logic to have the computer check for a blocking move or a winning move before it performs just a random move.

      This block of code is placed first to see if there is a move the computer can make to have it win the game and if there is such a move it will make this move

      for (int i = 0; i < getBOARD_SIZE(); i++)
      {
      if (mBoard[i] != HUMAN_PLAYER && mBoard[i] != ANDROID_PLAYER)
      {
      char curr = mBoard[i];
      mBoard[i] = ANDROID_PLAYER;
      if (checkForWinner() == 3)
      {
      setMove(ANDROID_PLAYER, i);
      return i;
      }
      else
      mBoard[i] = curr;
      }
      }

      Then if there is no place the computer can play in order to win the game we need to check and see if there is a space that it can play to block the player from winning. That is done in the second if block.

      for (int i = 0; i < getBOARD_SIZE(); i++)
      {
      if (mBoard[i] != HUMAN_PLAYER && mBoard[i] != ANDROID_PLAYER)
      {
      char curr = mBoard[i];
      mBoard[i] = HUMAN_PLAYER;
      if (checkForWinner() == 2)
      {
      setMove(ANDROID_PLAYER, i);
      return i;
      }
      else
      mBoard[i] = curr;
      }
      }

      If no winning or blocking move is available then we need to just let the computer randomly move somewhere which is done in this block of code:

      do
      {
      move = mRand.nextInt(getBOARD_SIZE());
      } while (mBoard[move] == HUMAN_PLAYER || mBoard[move] == ANDROID_PLAYER);

      Without checking for winning or blocking moves the game will be pretty easy to win and the computer will not offer up a challenge like it does currently.

      Delete