public GameState getGameState(BufferedImage screenshot) {

		// pixel colour deviation threshold for valid detection
		final int avgColourThreshold = 5;

		// check for main menu or episode menu or level selection
		BufferedImage wnd = screenshot.getSubimage(636, 24, 192, 26);
		

		int numBytes = 3 * wnd.getWidth() * wnd.getHeight();
		if (VisionUtils.imageDifference(wnd, _mainmenu) < numBytes
				* avgColourThreshold) {
			return GameState.MAIN_MENU;
		} else if (VisionUtils.imageDifference(wnd, _episodemenu) < numBytes
				* avgColourThreshold) {
			return GameState.EPISODE_MENU;
		} else if (VisionUtils.imageDifference(wnd, _levelselection) < numBytes
				* avgColourThreshold) {
			return GameState.LEVEL_SELECTION;
		} else if ((VisionUtils.imageDifference(wnd, _loading) < numBytes
				* avgColourThreshold)
				|| (VisionUtils.imageDifference(wnd, _loading2) < numBytes
						* avgColourThreshold)) {
			return GameState.LOADING;
		}
		// otherwise check for end game or playing
		wnd = screenshot.getSubimage(467, 350, 61, 60);
		numBytes = 3 * wnd.getWidth() * wnd.getHeight();
		if (VisionUtils.imageDifference(wnd, _gamewon1) < numBytes
				* avgColourThreshold || VisionUtils.imageDifference(wnd, _gamewon2) < numBytes
				* avgColourThreshold) {
			return GameState.WON;
		}
	

		wnd = screenshot.getSubimage(320, 112, 192, 26);
		numBytes = 3 * wnd.getWidth() * wnd.getHeight();
		if (VisionUtils.imageDifference(wnd, _gamelost) < numBytes
				* avgColourThreshold) {
			return GameState.LOST;
		}

		return GameState.PLAYING;
	}