亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? swingapplet.java

?? 用java寫的一個強化學習程序
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
//<APPLET CODE = "SwingApplet.class" WIDTH = 700 HEIGHT = 400 ></applet>

// load for early releases
//import com.sun.java.swing.*;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class SwingApplet extends JApplet implements ActionListener,Runnable{
	static final int BW=300, BH=300, BX=8, BY=8, NUM_WALLS=20,
		SAMP_W = 100, SAMP_H = 100;
	static final int DEF_EPOCHS = 50000;
	static final long DELAY=500;
	static int MAXX=400, MAXY=400;
	
	CatAndMouseGame game;
	CatAndMouseWorld trainWorld, playWorld; // seperate world from playing world
	RLController rlc;
	RLearner rl;
		
	JTabbedPane tabbedPane;
	Container instructions, playPanel, trainPanel, worldPanel;
	
	// world setting components
	JTextField rows, cols, obst;
	sampleWorlds samples;
	boolean[][] selectedWalls;
	ButtonGroup worldSelGroup;
	boolean sampleWorld=true, designWorld=false;
	
	// instructions components
	JLabel instructLabel, usageLabel;
	final String INSTRUCT_MESSAGE = "<html><p>This applet demonstrates how reinforcement <p>learning can be used to train an agent to play <p>a simple game.  In this case the game is Cat and <p>Mouse- the mouse tries to get to the cheese <p>and back to it's hole, the cat tries to catch the mouse.",
		USAGE_MESSAGE = "<html><p>You can train the agent by selecting the Train tab.  At <p>any time you can select the Play tab to see how <p>well the agent is performing!  Of course, the more <p>training, the better the chance the mouse <p>has of surviving :)";

	// train panel components
	public static final String START="S", CONT_CHECK="C";
	final String SETTINGS_TEXT = "These settings adjust some of the internal workings of the reinforcement learning algorithm.",
		SETTINGS_TEXT2 = "Please see the web pages for more details on what the parameters do.";
	JTextField alpha, gamma, epsilon, epochs, penalty, reward;
	JButton startTraining, stopTraining;
	JRadioButton softmax, greedy, sarsa, qlearn;
	JProgressBar progress;
	JLabel learnEpochsDone;	
	
	// play panel components
	JButton startbutt, stopbutt, pausebutt;
	boardPanel bp;
	public int mousescore=0, catscore =0;
	JLabel catscorelabel, mousescorelabel;
	final String MS_TEXT = "Mouse Score:", CS_TEXT = "Cat Score:";
	JSlider speed, smoothSlider;
	Image catImg, mouseImg;
	chartPanel graphPanel;
	JLabel winPerc;
			
	boardObject cat, mouse, cheese, back, hole, wall;

					
	public SwingApplet() {
		getRootPane().putClientProperty("defeatSystemEventQueueCheck",Boolean.TRUE);
		
	}
	
	public void init() {
		// load images
		catImg = getImage(getCodeBase(), "cat.gif");
		mouseImg = getImage(getCodeBase(), "mouse.gif");
		Image wallImg = getImage(getCodeBase(), "wall.gif");
		Image cheeseImg = getImage(getCodeBase(), "cheese.gif");
		Image floorImg = getImage(getCodeBase(), "floor.gif");
		
/*		Image catImg = getImage(ClassLoader.getSystemResource("cat.gif"));
		Image mouseImg = getImage(ClassLoader.getSystemResource("mouse.gif"));
		Image wallImg = getImage(ClassLoader.getSystemResource("wall.gif"));
		Image cheeseImg = getImage(ClassLoader.getSystemResource("cheese.gif"));*/

		// set up board objects
		cat = new boardObject(catImg);
		mouse = new boardObject(mouseImg);
		cheese = new boardObject(cheeseImg);
		back = new boardObject(floorImg);
		hole = new boardObject(Color.orange);
		wall = new boardObject(wallImg);
		
		// setup content panes
		tabbedPane = new JTabbedPane();
		
		//instructions = makeInstructions();
		worldPanel = makeWorldPanel();
		playPanel = makePlayPanel();
		trainPanel = makeTrainPanel();
		
		tabbedPane.addTab("World", worldPanel);
		tabbedPane.addTab("Play", playPanel);
		//tabbedPane.addTab("Instructions", instructions);
		tabbedPane.addTab("Train", trainPanel);
		tabbedPane.setSelectedIndex(0);

		// disable panes until world created
		tabbedPane.setEnabledAt(1,false);
		tabbedPane.setEnabledAt(2,false);
		
		// set up controls
		//setContentPane(new JPanel());
		//getContentPane().add(tabbedPane);
		
		getContentPane().add(tabbedPane);
	}

	public void worldInit(int xdim, int ydim, int numwalls) { 
		trainWorld = new CatAndMouseWorld(xdim, ydim,numwalls);
		gameInit(xdim,ydim);
	}
	public void worldInit(boolean[][] givenWalls) {
		int xdim = givenWalls.length, ydim = givenWalls[0].length;
		trainWorld = new CatAndMouseWorld(xdim, ydim,givenWalls);
		gameInit(xdim,ydim);		
	}
	private void gameInit(int xdim, int ydim) {
		// disable this pane
		tabbedPane.setEnabledAt(0,false);
		
		playWorld = new CatAndMouseWorld(xdim, ydim,trainWorld.walls);

		bp.setDimensions(xdim, ydim);
		
		rlc = new RLController(this, trainWorld, DELAY);
		rl = rlc.learner;
		rlc.start();
		
		game = new CatAndMouseGame(this, DELAY, playWorld, rl.getPolicy());
		game.start();

		// set text fields on panels
		penalty.setText(Integer.toString(trainWorld.deathPenalty));
		reward.setText(Integer.toString(trainWorld.cheeseReward));
		alpha.setText(Double.toString(rl.getAlpha()));
		gamma.setText(Double.toString(rl.getGamma()));
		epsilon.setText(Double.toString(rl.getEpsilon()));

		// enable other panes
		tabbedPane.setEnabledAt(1,true);
		tabbedPane.setEnabledAt(2,true);
		
		// switch active pane
		tabbedPane.setSelectedIndex(1);

		// set first position on board
		updateBoard();
	}
	
	// this method is triggered by SwingUtilities.invokeLater in other threads
	public void run() { updateBoard(); }
	
	/************ general functions ****************/
	public void updateBoard() {
		// update score panels
		mousescorelabel.setText(MS_TEXT+" "+Integer.toString(mousescore));
		catscorelabel.setText(CS_TEXT+" "+Integer.toString(catscore));
		if (game.newInfo) {
			updateScore();
			game.newInfo = false;
		}
		
		// update progress info
		progress.setValue(rlc.epochsdone);
		learnEpochsDone.setText(Integer.toString(rlc.totaldone));
		if (rlc.newInfo) endTraining();
		
		// update game board
		bp.clearBoard();

		// draw walls
		boolean[][] w = game.getWalls(); 
		for (int i=0; i<w.length; i++) {
			for (int j=0; j<w[0].length; j++) {
				if (w[i][j]) bp.setSquare(wall, i, j);
			}
		}

		// draw objects (cat over mouse over cheese)
		bp.setSquare(cheese, game.getCheese());
		bp.setSquare(mouse, game.getMouse());
		bp.setSquare(cat, game.getCat());
		//bp.setSquare(hole, game.getHole());
					
		// display text representation
		//System.out.println(bp);
		bp.repaint();
	}

	void doTraining() {
		// begin training
		int episodes = Integer.parseInt(epochs.getText());
		double aval = Double.parseDouble(alpha.getText());
		double gval = Double.parseDouble(gamma.getText());
		double eval = Double.parseDouble(epsilon.getText());
		int cval = Integer.parseInt(reward.getText());
		int dval = Integer.parseInt(penalty.getText());
				
		rl.setAlpha(aval);
		rl.setGamma(gval);
		rl.setEpsilon(eval);
				
		// disable controls
		startTraining.setEnabled(false);
		epochs.setEnabled(false);
		reward.setEnabled(false);
		penalty.setEnabled(false);
		alpha.setEnabled(false);
		gamma.setEnabled(false);
		epsilon.setEnabled(false);
		softmax.setEnabled(false);
		greedy.setEnabled(false);
		sarsa.setEnabled(false);
		qlearn.setEnabled(false);
				
		// fix progress bar
		progress.setMinimum(0);
		progress.setMaximum(episodes);
		progress.setValue(0);
				
		// enable stop button
		stopTraining.setEnabled(true);
				
		// start training
		trainWorld.cheeseReward = cval;
		trainWorld.deathPenalty = dval;
		rlc.setEpisodes(episodes);
	}

	void endTraining() {
		// stop training
		rlc.stopLearner();
		
		// enable buttons
		startTraining.setEnabled(true);
		epochs.setEnabled(true);
		reward.setEnabled(true);
		penalty.setEnabled(true);
		alpha.setEnabled(true);
		gamma.setEnabled(true);
		epsilon.setEnabled(true);
		softmax.setEnabled(true);
		greedy.setEnabled(true);
		sarsa.setEnabled(true);
		qlearn.setEnabled(true);

		// disable stop button
		stopTraining.setEnabled(false);
	}

	void updateScore() {
		double newScore = Math.round(1000*((double)mousescore)/(catscore + mousescore))/10;
		winPerc.setText(Double.toString(newScore)+"%");
		graphPanel.updateScores();
		graphPanel.repaint();
		game.gameActive = true;		
	}	
	/************ general functions ****************/

	/********** Methods to construct panels *************/
	Container makeWorldPanel() {
		JPanel worldPane = new JPanel();
		worldPane.setLayout(new BorderLayout());

		worldSelGroup = new ButtonGroup();
		
		worldPane.add(chooseWorld(), BorderLayout.CENTER);
		//worldPane.add(customWorld(), BorderLayout.EAST);
		JButton startbutt = new JButton("Click here to start!");
		startbutt.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// selected world type, choose action
				if (sampleWorld) {
					worldInit(selectedWalls);
				} else if (designWorld) {
					// custom designed world
				
				} else {
					// random world
					worldInit(Integer.parseInt(cols.getText()),
						Integer.parseInt(rows.getText()),
						Integer.parseInt(obst.getText()));
				}
			}
		});
		worldPane.add(startbutt, BorderLayout.SOUTH);
		return worldPane;
	}
	
	Container customWorld() {
		JPanel pane = new JPanel();
		pane.setLayout(new BorderLayout());
		
		JRadioButton random = new JRadioButton("Random World");
		random.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// enable obstacles field
				obst.setEnabled(true);
				designWorld=false;
				sampleWorld=false;
			}
		});
		worldSelGroup.add(random);
		pane.add(random, BorderLayout.NORTH);
		
		/*JRadioButton custom = new JRadioButton("Custom Design");
		custom.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// enable obstacles field
				obst.setEnabled(false);
				designWorld=true;
				sampleWorld=false;
			}
		});*/
		
		// add controls to set dimensions
		JPanel labelpane = new JPanel();
		labelpane.setLayout(new GridLayout(0,2));

		//worldSelGroup.add(custom);
		
		//JPanel controls = new JPanel();
		//controls.setLayout(new GridLayout(0,1));
		rows = new JTextField(Integer.toString(BY), 20);
		cols = new JTextField(Integer.toString(BX), 20);
		obst = new JTextField(Integer.toString(NUM_WALLS), 20);
		
		labelpane.add(new JLabel("Rows:",JLabel.RIGHT));
		labelpane.add(rows);
		labelpane.add(new JLabel("Columns:",JLabel.RIGHT));
		labelpane.add(cols);
		labelpane.add(new JLabel("Obstacles:",JLabel.RIGHT));
		labelpane.add(obst);
		
		//labelpane.setBorder(BorderFactory.createTitledBorder("Custom World"));
		//labelpane.add(random);
		//labelpane.add(custom);

		pane.add(labelpane, BorderLayout.CENTER);
		//pane.add(controls, BorderLayout.EAST);
		//pane.add(labelpane);
		//pane.add(controls);
		
		return pane;	
	}
	
	Container chooseWorld() {
		JPanel pane = new JPanel();
		pane.setLayout(new GridLayout(0,3));

		// grab each sample
		samples = new sampleWorlds();
		for (int i=0; i<samples.numSamples(); i++) {
			JPanel thisPanel = new JPanel();
			thisPanel.setLayout(new BorderLayout());
			
			// set first as selected
			if (i==0) selectedWalls = samples.getWalls(i);
			
			JRadioButton b = new JRadioButton(samples.getTitle(i), (i==0));
			b.setHorizontalAlignment(SwingConstants.LEFT);
			b.setActionCommand(Integer.toString(i));
			b.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					int index = Integer.parseInt(e.getActionCommand());
					selectedWalls = samples.getWalls(index);
					sampleWorld=true;
				}
			});
			
			boolean[][] w = samples.getWalls(i);
			
			// create boardPanel object for this world
			boardPanel pic = new boardPanel(back, w.length, w[0].length,SAMP_W, SAMP_H);
			// add walls to panel
			for (int x=0; x<w.length; x++)
				for (int y=0; y<w.length; y++)
					if (w[x][y]) pic.setSquare(wall, x, y);
			
			worldSelGroup.add(b); // add to button group
			pic.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
			
			thisPanel.add(pic, BorderLayout.CENTER);
			thisPanel.add(b, BorderLayout.NORTH); // add to pane
			thisPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
			
			pane.add(thisPanel);
		}

		// add random world option
		pane.add(customWorld());
		pane.setBorder(BorderFactory.createTitledBorder("Choose World"));
		return pane;
	}
	
	Container makeInstructions() {
		JPanel pane = new JPanel();
		pane.setLayout(new GridLayout(2,1));
		
		instructLabel = new JLabel(INSTRUCT_MESSAGE);
		usageLabel = new JLabel(USAGE_MESSAGE);
		

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91原创在线视频| 国产精品1024| 欧美三级一区二区| 亚洲欧美另类小说| 午夜日韩在线观看| 91小视频在线| 亚洲欧美日韩精品久久久久| 91欧美一区二区| 无吗不卡中文字幕| 欧美成人性战久久| av电影在线观看不卡| 一区二区三区四区视频精品免费| 欧美影院一区二区| 狠狠色狠狠色综合| 国产日韩亚洲欧美综合| 色婷婷av一区二区三区软件| 日韩高清在线一区| 久久九九影视网| 91福利视频在线| 免费在线观看精品| 日本一二三不卡| 欧美精品v国产精品v日韩精品| 美女久久久精品| 中文字幕视频一区| 91麻豆精品国产综合久久久久久 | 精品免费日韩av| 不卡一区二区在线| 日日摸夜夜添夜夜添精品视频| 欧美精品一区视频| 色网综合在线观看| 国产最新精品精品你懂的| 亚洲免费av在线| 久久日韩精品一区二区五区| 在线观看日韩毛片| 国产美女视频91| 一二三区精品视频| 久久久国际精品| 欧美日韩亚州综合| 成人午夜视频在线| 久久精品国产一区二区| 中文字幕一区二区三区蜜月| 欧美精品一区二区三区在线播放| 91偷拍与自偷拍精品| 激情综合五月婷婷| 五月综合激情网| 亚洲欧美经典视频| 久久久电影一区二区三区| 欧美日本一道本在线视频| 99久久伊人精品| 国产精品亚洲第一区在线暖暖韩国| 午夜视频在线观看一区二区| 亚洲免费视频成人| 国产人成亚洲第一网站在线播放| 欧美男人的天堂一二区| 日本电影亚洲天堂一区| 成人av影视在线观看| 国产高清精品网站| 久久电影网站中文字幕| 亚洲小说春色综合另类电影| 国产精品久久久久影院色老大| 日韩精品一区二区三区四区| 欧美丰满少妇xxxbbb| 91国模大尺度私拍在线视频| 色综合网站在线| 99国产精品久久久久久久久久| 久久99蜜桃精品| 久久国产精品色婷婷| 免费的国产精品| 久草中文综合在线| 美女一区二区在线观看| 另类的小说在线视频另类成人小视频在线| 亚洲精品欧美在线| 亚洲女同一区二区| 亚洲精品菠萝久久久久久久| 国产人久久人人人人爽| 国产精品久久久久影院色老大| 国产女人18毛片水真多成人如厕| 国产亚洲一区二区三区四区| 久久精品视频一区二区三区| 国产欧美日本一区二区三区| 国产亚洲欧美日韩俺去了| 亚洲精品一区二区三区香蕉| 久久久亚洲午夜电影| 久久久久久久综合色一本| 国产视频一区在线播放| 国产欧美日韩精品a在线观看| 国产精品久久久久三级| 亚洲少妇30p| 亚洲va欧美va人人爽午夜| 天天综合天天综合色| 青青草97国产精品免费观看无弹窗版| 久久精品国产精品亚洲红杏| 久草这里只有精品视频| 国产白丝精品91爽爽久久| 国产成人av一区二区| 欧美中文字幕一区二区三区| 在线视频观看一区| 538在线一区二区精品国产| 日韩一区二区三区在线视频| 2023国产一二三区日本精品2022| 国产丝袜欧美中文另类| 夜色激情一区二区| 免费观看一级欧美片| 国产成人在线视频免费播放| 91在线视频在线| 91精品国产综合久久久久久久久久| 精品久久久久99| 亚洲人精品午夜| 麻豆免费精品视频| 99视频精品全部免费在线| 91精品国产综合久久小美女| 久久久久国产精品厨房| 曰韩精品一区二区| 久久99精品国产91久久来源| 99久久国产综合精品女不卡| 欧美日韩国产中文| 国产视频911| 亚洲一卡二卡三卡四卡无卡久久 | 亚洲妇熟xx妇色黄| 蜜桃视频在线一区| 色综合天天在线| 2021国产精品久久精品| 国产精品久久久久久久蜜臀| 婷婷成人激情在线网| 成人激情小说网站| 欧美一卡二卡三卡四卡| 亚洲精品乱码久久久久| 看电影不卡的网站| 91福利资源站| 国产精品婷婷午夜在线观看| 日本一不卡视频| 91福利精品视频| 国产清纯白嫩初高生在线观看91 | 色拍拍在线精品视频8848| 欧美一区二区三区思思人| 自拍偷拍亚洲欧美日韩| 美国一区二区三区在线播放| 91国产免费观看| 国产精品无遮挡| 国产一区二三区| 欧美日韩你懂的| 亚洲美女免费在线| 国产91在线|亚洲| 日韩精品一区二区三区蜜臀| 亚洲第一会所有码转帖| 欧美日韩国产三级| 亚洲男同1069视频| 成年人午夜久久久| 久久网站热最新地址| 午夜国产精品影院在线观看| 91视频国产观看| 国产精品久久久久精k8| 国产精品一卡二卡| 久久色中文字幕| 激情五月婷婷综合网| 日韩欧美亚洲国产另类| 亚洲成人免费在线观看| 一本久道久久综合中文字幕| 中文字幕乱码亚洲精品一区| 风间由美性色一区二区三区| 久久综合色综合88| 久久99深爱久久99精品| 日韩一卡二卡三卡国产欧美| 日韩高清在线观看| 日韩限制级电影在线观看| 亚洲mv大片欧洲mv大片精品| 欧美婷婷六月丁香综合色| 亚洲你懂的在线视频| 日本电影欧美片| 一区二区三区不卡视频| 欧美三级日韩三级| 日本亚洲视频在线| 日韩欧美国产电影| 欧美a级一区二区| 精品99一区二区| 国产一区二区三区精品欧美日韩一区二区三区| 欧美日韩高清一区二区三区| 三级欧美韩日大片在线看| 欧美精品在欧美一区二区少妇| 亚洲成人1区2区| 51精品久久久久久久蜜臀| 日韩电影在线免费看| 日韩欧美视频在线| 麻豆成人久久精品二区三区小说| 欧美刺激脚交jootjob| 国产麻豆视频一区| 国产精品高潮呻吟久久| 91福利小视频| 久久国产生活片100| 国产精品久久久久久久久免费桃花| 97久久精品人人做人人爽| 亚洲国产你懂的| 日韩欧美黄色影院| 国产一区不卡视频| 亚洲视频一区在线观看| 这里只有精品免费| 成人少妇影院yyyy| 一区二区三区四区视频精品免费| 在线观看91av| 成人亚洲精品久久久久软件|