Go to Post Teams are overconfident every year. Honest evaluation of your capabilities with regard to your design strategy is a skill few teams have. - Chris is me [more]
Home
Go Back   Chief Delphi > Competition > Rules/Strategy
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-01-2007, 21:55
b_mallerd b_mallerd is offline
Programmer
FRC #1346 (Trobotics)
Team Role: Programmer
 
Join Date: Dec 2005
Rookie Year: 2005
Location: Vancouver
Posts: 35
b_mallerd is on a distinguished road
Send a message via MSN to b_mallerd
Minimalist Scoring Program

This is just some code I hacked up to keep track of a board and the current scores.

It runs through terminal in blue j (java IDE), but it would probably run through just cmd.

I just wanted to develop a way to quickly keep track of the score. This is all text based so at the input prompt you would enter something like

x,1,1

meaning put x on position 1,1 of the grid. it goes [row],[column].

I'm thinking about making it web-based (idea from sundial) with some human watchers updating to a central server as the game progresses. This means people in the pits would have some idea of how the games are progressing.
This may not happen because season has started, but who knows.

Unforutunately there are no spoilers yet implemented and anything can just be simply removed. This is just an elaborate game of tic tac toe with scoring.

Please use the code as would suit you best.


Code:
import java.util.*;

public class RackandRoll
{
    
    public static int board[][] = { {0,0,0,0,0,0,0,0},
                                    {0,0,0,0,0,0,0,0},
                                    {0,0,0,0,0,0,0,0},
                                   };
    public static final int ROWS = 3,COLUMNS = 8;
    public static final int X = 1, O = 2,EMPTY = 0;
    public static int XScore,OScore;
   
    
    
    public static void printBoard()
    {
        for(int c=0;c<30;c++)
            System.out.println();
        
        System.out.print("  |");
        for(int i=0;i<COLUMNS;i++)
            System.out.print(" " + (i+1) + " |");
            
        System.out.println();
        
        for(int i=0;i<ROWS;i++)
        {
            System.out.print(i+1+ " |");
            
            for(int k=0;k<COLUMNS;k++)
            {
                switch (board[i][k]){
                    
                    case X:
                        System.out.print(" " + 'X' + " ");
                        break;
                    case O:
                        System.out.print(" " + 'O' + " ");
                        break;
                    case EMPTY:
                        System.out.print("   ");
                        break;
               }
               
               System.out.print("|");
            }
            
            System.out.println();
          
        }
        
        getXScore();
        getOScore();
        
        System.out.println();
        System.out.println("X score is: " + XScore );
        System.out.println("O score is: " + OScore );
        

   }
   
   public static int getInput()
   {
       Scanner sc = new Scanner(System.in);
       int value=0;
       
       System.out.println("[X or O or e],[row],[column]");
       System.out.print("Input>>");
       StringTokenizer st = new StringTokenizer(sc.next(),", ");
        

        
       switch (st.nextToken().charAt(0))
       {
           case 'x':
                value = X;
                break;
           case 'o' :
                value = O;
                break;
           case 'q':
                value = -1;
                break;
           default:
                value = EMPTY;
        }
        
      
        if(value == -1)
            return value;
            
        int row = Integer.valueOf(st.nextToken())-1;
        int column = Integer.valueOf(st.nextToken())-1;
        
        if(row > 2 || row < 0 || column > 7 || column < 0)
            return 0;
        
        board[row][column] = value;
        return 0;
        
    }
    
    public static void getXScore()
    {
        int score=0,cnt=0;
        int i,k;
        
        for(i=0;i<3;i++) //score for horz. rows
        {
            for(k=0;k<8;k++)
            {
                if(board[i][k] == X)
                {
                    cnt++;
                }
                
                if( k==7 || board[i][k+1] != X)
                {
                    if(cnt > 0)
                    score += Math.pow(2,cnt);
                    
                    cnt=0;
                }
            }
            
            
        }
       
        cnt = 0;
        
         for(k=0;k<8;k++) //score for horz. rows
        {
            for(i=0;i<3;i++)
            {
                if(board[i][k] == X)
                {
                    cnt++;
                }
                
                if( i==2 || board[i+1][k] != X)
                {
                    if(cnt > 0)
                    score += Math.pow(2,cnt);
                    
                    cnt=0;
                }
            }
            
            
        }
        
        XScore = score;
        
    }
    
        public static void getOScore()
    {
        int score=0,cnt=0;
        int i,k;
        
        for(i=0;i<3;i++) //score for horz. rows
        {
            for(k=0;k<8;k++)
            {
                if(board[i][k] == O)
                {
                    cnt++;
                }
                
                if( k==7 || board[i][k+1] != O)
                {
                    if(cnt > 0)
                    score += Math.pow(2,cnt);
                    
                    cnt=0;
                }
            }
            
            
        }
       
        cnt = 0;
        
         for(k=0;k<8;k++) //score for horz. rows
        {
            for(i=0;i<3;i++)
            {
                if(board[i][k] == O)
                {
                    cnt++;
                }
                
                if( i==2 || board[i+1][k] != O)
                {
                    if(cnt > 0)
                    score += Math.pow(2,cnt);
                    
                    cnt=0;
                }
            }
            
            
        }
        
        OScore = score;
        
    }
            
        
       

   public static void main(String args[])
   {
      int i=0;

      do
      {
          printBoard();
          i = getInput();
      }while(i != -1);
          
    }

}
__________________
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scoring Program LukeMX General Forum 14 09-01-2005 12:54
FIRST Scoring Program MikeDubreuil Programming 8 11-02-2004 21:45
Scoring Program TimA Rules/Strategy 2 11-01-2004 18:27
Scoring Program archiver 2001 1 24-06-2002 01:05
Scoring Program archiver 2001 7 23-06-2002 23:03


All times are GMT -5. The time now is 07:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi