我试图在Google Compute Engine VM上运行CartPole-v0示例。 https://gym.openai.com/docs
package com.example.contentprovider;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class MainActivity extends AppCompatActivity {
// Cursor Adapter for storing contacts data
SimpleCursorAdapter adapter;
// List View Widget
ListView lvContacts;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Init ListView
lvContacts = (ListView) findViewById(R.id.lvContacts);
// Initialize Content Resolver object to work with content Provider
ContentResolver cr = getContentResolver();
// Read Contacts
Cursor c = cr.query(ContactsContract.Contacts.CONTENT_URI,
new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }, null, null,
null);
// Attached with cursor with Adapter
adapter = new SimpleCursorAdapter(this, R.layout.row, c,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { R.id.lblName });
// Display data in listview
lvContacts.setAdapter(adapter);
}
}
我安装了XQuartz,ssh使用-X。
首先,我得到了 pyglet.canvas.xlib.NoSuchDisplayException:无法连接到"无"
然后根据http://www.gitterforum.com/discussion/openai-gym?page=28,我使用" xvfb-run -s" -screen 0 1400x900x24" /斌/庆典"
然后结果运行良好:
import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample()) # take a random action
但是没有任何渲染......