int* getButtons()
{
	static int buttons[] = {0,0,0,0};

	//Get touch sensor inputs
	long value = 1023-SensorRaw(S2);
	long switches = 339 * value;
	switches /= (1023-value);
	switches += 5;
	switches /= 10;
	if(switches&8)
		buttons[0] = 1;
	else
		buttons[0] = 0;
	if(switches&4)
		buttons[1] = 1;
	else
		buttons[1] = 0;
	if(switches&2)
		buttons[2] = 1;
	else
		buttons[2] = 0;
	if(switches&1)
		buttons[3] = 1;
	else
		buttons[3] = 0;
	return buttons;
}
int P_moveUpdate(int *emptiesToCheck)
{
	//Assumed home position is at 3,-2
	int curCol = -2;
	int curRow = 3;
	//moves to each column
	for(int i = 0; i < MAXCOL; i ++)
	{
		moveHor(curCol, i);
		curCol = i;
		wait1Msec(stabilize);

	//if it is necessary to check for a piece in this column
		if (emptiesToCheck[i] >= 0)
		{
				moveVert(curRow, emptiesToCheck[i]);
				curRow = emptiesToCheck[i];

			displayString(MAXROW+2, "check Row: %i ", curRow);
			displayString(MAXROW+3, "check Col: %i ", curCol);
		if (SensorRaw(S2) > redVal)
			{
				GameBoard[curRow][curCol] = 1; 
				//updates gameboard that a piece is there
				displayGameBoard();
				updateEmpties(emptiesToCheck);
				displayEmpties(emptiesToCheck);
				playSound(soundBeepBeep); 
				moveVert(curRow, 3); //resets light sensor to bottom
				return curCol;
			}
		}
	}
	moveVert(curRow, 3); //resets light sensor to bottom
	return curCol; //in theory, this will never be required, just for compiling
}
task main()
{
	initializeRobot();

	ereset();

	waitForStart();

	ch = 1;

	brake();
	wait1Msec(300);
	{
		motor[motorH] = 50;
		motor[motorI] = 50;
		wait1Msec(300);
		motor[motorH] = 0;
		motor[motorI] = 0;

		movebackward();
		wait1Msec(2000);

		servo[servo3] = 247;

		brake(); //temporary stop
		wait1Msec(300);

		turnleft(); //turn  left to face the center goal structure
		wait1Msec(1100);

		brake(); //temporary stop
		wait1Msec(100);

		turnright();
		wait1Msec(1100);

		brake();
		wait1Msec(100);

		movebackward();// move forward to the center goal structure
		wait1Msec(2525);

		brake();
		wait1Msec(1000);

		if (SensorRaw(irs) > 3 && SensorRaw(irs) < 7)//checks for the ir value to know if the center goal structure is at postion 1
		{ //center goal structure is in the 1

			moveforward(); // move forward to be adjacent to the kickstand
			wait1Msec(650);

			brake(); //temporary stop
			wait1Msec(50);

			turnright(); //turn right to face the kickstand
			wait1Msec(1550);

			brake(); //temporary stop
			wait1Msec(100);

			moveforward(); //moveforward to knock down the kickstand and to be adjacent to the ir beacon and center goal
			wait1Msec(1250);

			brake();
			wait10Msec(3000);

			motor[motorH] = -50;//resets the initialize
			motor[motorI] = -50;
			wait1Msec(300);
			motor[motorH] = 0;//stops the 80/20 so that it does not move
			motor[motorI] = 0;
		}

		else if(SensorRaw(irs) <= 3 || SensorRaw(irs) >= 7)//if the ir sensor senses a value between 3 and 7
		{ //center goal is in position 2/3
			movebackward();//move the robot back to be adjacent to the ir beacon
			wait1Msec(900);

			turnleft();//turns left to check for position 2.
			wait1Msec(900);

			movebackward();//moves abckwards to be next to the ir beacon
			wait1Msec(1250);

			ch = 0;//gives the integer chicks the value of of 0
		}

		if (SensorRaw(irs) >= 7 && SensorRaw(irs) <= 8)//if ir value is between 7 and 8
		{ //center goal structure is in the 3 position

			while(SensorRaw(irs) < 5)//if it senses a value less than 5 until it senses at 5
			{
				movebackward();
			}
			moveforward();//moves the robot forward to be adjacent to the
			wait1Msec(500);

			turnright();//turn right to face the kickstand
			wait1Msec(900);

			moveforward();//knocks down the kickstand
			wait1Msec(1000);
		}

		else
		{ //center goal structure is in the 2 position
			moveforward();//move forward to be adjacent to the kickstand
			wait1Msec(1259);

			turnright();//turn right to face the kickstand
			wait1Msec(1600);

			moveforward();//move forward to knock down the kickstand
			wait1Msec(1500);
		}
	}
}