@Test public void testQTable() { final QTable t = getTestTable(); try { t.getColumnIndex("unknown"); fail("NullPointerException was expected"); } catch (NullPointerException e) { assertTrue(true); } catch (Exception e) { fail("NullPointerException was expected"); } assertEquals(0, t.getColumnIndex("f")); assertTrue(t.hasColumn("f")); assertFalse(t.hasColumn("unknown")); assertEquals(t, t); assertEquals(t, getTestTable()); int i = 0; final Iterator<Row> it = t.iterator(); while (it.hasNext()) { final Row row = it.next(); final Iterator<Object> cit = row.iterator(); int j = 0; while (cit.hasNext()) { final Object v = cit.next(); assertEquals(t.get(i).get(j), v); j++; } assertEquals(t.getColumnsCount(), j); i++; } assertEquals(t.getRowsCount(), i); }
void runLearningLoop() { QTable q = new QTable(getActionRange()); int moveCounter = 0; int count = 0; while (count < 100) { // PRINT MAP // printMap(); // CHECK IF WON, THEN RESET if (isGoalReached()) { System.out.println("GOAL REACHED IN " + moveCounter + " MOVES!"); resetMaze(); moveCounter = 0; count++; // q.updateQvalue(100, map); // return; } // DETERMINE ACTION int action = q.getNextAction(getMap()); // System.out.println(action+"MOVING: "+getMoveName(action)); goToNextState(action); moveCounter++; // REWARDS AND ADJUSTMENT OF WEIGHTS SHOULD TAKE PLACE HERE if (isGoalReached()) { q.updateQvalue(1, map); } else { q.updateQvalue(-100, map); } // COMMENT THE SLEEP FUNCTION IF YOU NEED FAST TRAINING WITHOUT // NEEDING TO ACTUALLY SEE IT PROGRESS // Thread.sleep(1000); } }