Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package abertay.xogame;
- import boardgameClasses.Board;
- public class Intelligence {
- public int intel(Board board){
- boolean loop=true;
- //flag to allow skipping of code if a value has been returned
- if (loop==true){
- //loop for columns
- for (int a=0; a< 7; a++){
- for (int b=0; b<3; b++){
- if ((board.get_state(a,b) ==1) &&
- board.get_state(a,b)==board.get_state(a,b+1) &&
- board.get_state(a,b)==board.get_state(a,b+2) && board.get_state(a,b+3)==0 )
- {
- loop=false;
- return a;
- }
- }
- }
- }
- //rows
- if (loop==true){
- for (int a=0; a< 6; a++){
- for (int b=0; b<4; b++){
- if ((board.get_state(b,a) ==1) &&
- board.get_state(b,a)==board.get_state(b+1,a) &&
- board.get_state(b,a)==board.get_state(b+2,a)&& //MIGHT HAVE TO CHANGE TO EQUALS 1 OR 2
- ((board.get_state(b+3,a)==0 && board.get_state(b+3,a-1)!=0) | (board.get_state(b-1,a-1)!=0 && board.get_state(b-1,a)==0)))
- {
- if (board.get_state(b+3,a)==0 && board.get_state(b+3,a-1)!=0){
- loop=false;
- return (b+3);
- }
- else if (board.get_state(b-1,a-1)!=0 && board.get_state(b-1,a)==0){
- loop=false;
- return (b-1);
- }
- }
- }
- }
- }
- //diagonal to the right
- if (loop==true){
- for (int a=0; a< 4; a++){
- for (int b=0; b<3; b++){
- if ((board.get_state(a,b) ==1) &&
- board.get_state(a,b)==board.get_state(a+1,b+1) &&
- board.get_state(a,b)==board.get_state(a+2,b+2) &&
- //checking if a piece can be put either side of the diagonal
- ((board.get_state(a+3,b+3)==0 && (board.get_state(a+3,b+2)!=0) ) | (board.get_state(a-1,b-1)==0 && !(a<0)) && !(b<0)) )
- {
- //top of diagonal
- if ((board.get_state(a+3,b+3)==0 && ((board.get_state(a+3,b+2)!=0)) )){
- loop=false;
- return (a+3);
- }
- //bottom of diagonal [MIGHT NEED TO FIX END OF IF STATEMENT TO EQUAL 1 OR 2]
- else if ((board.get_state(a-1,b-1)==0 && !(a<0)) && !(b<0) && (board.get_state(a-1,b-2)!=0)){
- loop=false;
- return (a-1);
- }
- }
- }
- }
- }
- //diagonal to the left
- if (loop==true){
- for (int a=4; a< 7; a++){
- for (int b=0; b<3; b++){
- if ((board.get_state(a,b) ==1) &&
- board.get_state(a,b)==board.get_state(a-1,b+1) &&
- board.get_state(a,b)==board.get_state(a-2,b+2) &&
- ((board.get_state(a-3,b+3)==0) && (board.get_state(a-3, b+2)!=0) | (board.get_state(a+1,b-1) ==0 && !(a<0)) && !(b<0)) )
- {
- if ((board.get_state(a-3,b+3)==0) && (board.get_state(a-3, b+2)!=0)){
- loop=false;
- return (a-3);
- }
- else if ((board.get_state(a+1,b-1) ==0 && !(a<0)) && !(b<0) && (board.get_state(a+1,b-2) !=0)){
- loop=false;
- return (a+1);
- }
- }
- }
- }
- }
- //for anticipating 4 in a row, when there are only two in a row, with 1 space either side of them
- //rows
- /*if (loop==true){
- for (int a=0; a< 6; a++){
- for (int b=0; b<4; b++){
- if ((board.get_state(b,a) !=0) &&
- board.get_state(b,a)==board.get_state(b+1,a) &&
- ((board.get_state(b+2,a)==0) | (board.get_state(b-1,a)==0)))
- {
- if (board.get_state(b+2,a)==0){
- loop=false;
- return (b+3);
- }
- else if (board.get_state(b-1,a)==0){
- loop=false;
- return (b-1);
- }
- }
- }
- }
- }
- */
- //columns
- if (loop==true){
- for (int a=0; a< 7; a++){
- for (int b=0; b<3; b++){
- if ((board.get_state(a,b) !=0) &&
- board.get_state(a,b)==board.get_state(a,b+1) &&
- board.get_state(a,b+2)==0)
- {
- loop=false;
- return a;
- }
- }
- }
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement