0

So the assignment is to make a Rock Paper Scissors Spock Lizard Player that plays against another student's player without using any Random generation for 100000 trials. We are supposed to be able to detect the patterns/sequences in the other player by storing their past moves and looking for any repeating sequences.

I'm doing a code in which I store the past moves in a two-dimensional array (but i don't really find a use for the second dimension?), and I keep checking if there is any repeating sequences within the past moves every time as the number of trials increase. But my code is piling up, I want to put it in a loop in which I can just run it for the number of turns that has happened.

Here's the part where I do the check, it's a lot of coding and I'm trying to figure out a way to compress it. Also, is there any way to store the past opponent moves using perhaps multi-dimensional arrays? Apparently, the teacher said that it would be good if we could do that, but I couldn't really think of a way in which it could be useful.

if ((pastOppMoves[turnNumber-1][0]==pastOppMoves[turnNumber-2][0]) 
				&&(pastOppMoves[turnNumber-2][0]==pastOppMoves[turnNumber-3][0]))
		{
			return 1;//one repeating move
		}

		if (turnNumber>=4)
		{
			if ((pastOppMoves[turnNumber-1][0]==pastOppMoves[turnNumber-3][0])
					&&(pastOppMoves[turnNumber-2][0]==pastOppMoves[turnNumber-4][0]))
			{
				return 2;//two moves switching back and forth
			}

			if (turnNumber>=6)
			{
				if ((pastOppMoves[turnNumber-1][0]==pastOppMoves[turnNumber-4][0])
						&&(pastOppMoves[turnNumber-2][0]==pastOppMoves[turnNumber-5][0])
						&&(pastOppMoves[turnNumber-3][0]==pastOppMoves[turnNumber-6][0]))
				{
					return 3;//three moves switching back and forth
				}
				if (turnNumber>=8)
				{
					if ((pastOppMoves[turnNumber-1][0]==pastOppMoves[turnNumber-5][0])
							&&(pastOppMoves[turnNumber-2][0]==pastOppMoves[turnNumber-6][0])
							&&(pastOppMoves[turnNumber-3][0]==pastOppMoves[turnNumber-7][0])
							&&(pastOppMoves[turnNumber-4][0]==pastOppMoves[turnNumber-8][0]))
					{
						return 4;//four moves switching back and forth
					}

					if (turnNumber>=10)
					{
						if ((pastOppMoves[turnNumber-1][0]==pastOppMoves[turnNumber-6][0])
								&&(pastOppMoves[turnNumber-2][0]==pastOppMoves[turnNumber-7][0])
								&&(pastOppMoves[turnNumber-3][0]==pastOppMoves[turnNumber-8][0])
								&&(pastOppMoves[turnNumber-4][0]==pastOppMoves[turnNumber-9][0])
								&&(pastOppMoves[turnNumber-5][0]==pastOppMoves[turnNumber-10][0]))
						{
							return 5;//five moves switching back and forth
						}

						if (turnNumber>=20)
						{
							if ((pastOppMoves[turnNumber-1][0]==pastOppMoves[turnNumber-11][0])
									&&(pastOppMoves[turnNumber-2][0]==pastOppMoves[turnNumber-12][0])
									&&(pastOppMoves[turnNumber-3][0]==pastOppMoves[turnNumber-13][0])
									&&(pastOppMoves[turnNumber-4][0]==pastOppMoves[turnNumber-14][0])
									&&(pastOppMoves[turnNumber-5][0]==pastOppMoves[turnNumber-15][0]))
								
							{
								return 6;
							}
						}

					}
				}
			}
		}

Edited by flyingcurry: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by quuba
0
static int test2(int T, int[] M, int LIMIT) {
        System.out.println("LIMIT " + LIMIT);
        System.out.println("T " + T);
        System.out.println("====");
        int B = 2;
        int H = B / 2;
        while (LIMIT > B) {
            System.out.println("B " + B);
            int counter = 0;
            if (T >= B) {
                for (int i = 0; i < H; i++) {
                    System.out.println("[" + (T - H + i) + "," + (T - B + i) + "]");
                    if (M[T - H + i] == M[T - B + i]) {
                        counter++;
                    }
                    // System.out.println("[" + M[T - H + i] + "," + M[T - B + i] + "]");
                }
                if (counter == H) {
                    return H;
                }
            }
            B += 2;
            H = B / 2;
            System.out.println("----");
        }
        return 0;
    }

    public static void main(String[] args) {
        int LIMIT = 30;
        int T = 2;
        int[] M = new int[200];
        for (int i = 0; i < 200; i++) {
            M[i] = i;
        }
        while (T < 30) {
            int R = test2(T, M, LIMIT);
            System.out.println("---- " + R);
            T++;
        }
    }

develop:

1.change names
2.parametrize
3.search relations
4.count lines with == , transform logical && to arithmetical +
5.found step for B
6.found while-condition-loop
7.write negative test with own indexed array
                    
                    B += 2; // B = 8;
                    int H = B / 2;// 4
                    int counter = 0;
                    if (T >= B) {
                        for (int i = 0; i < H; i++) {
                            if (M[T - H + i] == M[T - B + i]) {
                                counter++;
                            }
                        }
                        if (counter == H) {
                            return H;
                        }
                        .....
                        /*                        
                        if (
                        
                        (M[T - H-3] == M[T - B-3])
                        && (M[T - H-2] == M[T - B-2])
                        && (M[T - H-1] == M[T - B-1])
                        && (M[T - H] == M[T - B])
                        
                        ) {
                        return 4;//four moves switching back and forth
                        }
                         */

Read about Markov chain

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.