1 / 42

David Evans cs.virginia/evans

Lecture 21: Here Be Snakes. David Evans http://www.cs.virginia.edu/evans. CS201j: Engineering Software University of Virginia Computer Science. Menu. Exam 2 Comments (CS201J condensed) Computer Science (CS200 condensed) Networking (CS457 condensed) Game playing (CS416 condensed).

Download Presentation

David Evans cs.virginia/evans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 21: Here Be Snakes David Evans http://www.cs.virginia.edu/evans CS201j: Engineering Software University of Virginia Computer Science

  2. Menu • Exam 2 Comments (CS201J condensed) • Computer Science (CS200 condensed) • Networking (CS457 condensed) • Game playing (CS416 condensed) CS 201J Fall 2002

  3. CS201J Really Condensed “abstract” “design” “impossible”, “challenge”, “a lot of work” “thought provoking”, “spine-tingling” “changing the world” “smart safe secure coding class” “thorough program analysis” “efficient software development” CS 201J Fall 2002

  4. CS201J Condensed, more responses “how to program if you aren’t a lazy bastard” “programming with the knowledge that errors will happen and using that knowledge to survive such errors” “learning to write code that other people can actually use” “a safe playground for imagination” “not your everyday computer science course” “an exercise in humility”, “frustration by specification” “Small Hall”, “language tricks overview” “explores techniques and tools for constructing robust, complex and secure software” “adaptable tools for software programming and design” “secure programming” CS 201J Fall 2002

  5. CS201J Condensed – My Answer abstraction Using abstraction to manage complexity CS 201J Fall 2002

  6. Abstraction From Gerard Holzmann’s FSE Slides CS 201J Fall 2002

  7. Abstraction in CS201J • Abstraction by Specification • Abstract away how details by saying what a procedure does • Data Abstraction • Abstract away representation details by specifying what you can do with something • Subtyping • Abstract away actual type details by allowing many types to be used in the same way (?) • Concurrency • Abstract away when details (?) CS 201J Fall 2002

  8. Is CS201J a Computer Science class? CS 201J Fall 2002

  9. What is Computer Science? CS 201J Fall 2002

  10. Let AB and CD be the two given numbers not relatively prime. It is required to find the greatest common measure of AB and CD. If now CD measures AB, since it also measures itself, then CD is a common measure of CD and AB. And it is manifest that it is also the greatest, for no greater number than CD measures CD. But, if CD does not measure AB, then, when the less of the numbers AB and CD being continually subtracted from the greater, some number is left which measures the one before it. Euclid’s Elements, Book VII, Proposition 2 (300BC) CS 201J Fall 2002

  11. By the word operation, we mean any process which alters the mutual relation of two or more things, be this relation of what kind it may. This is the most general definition, and would include all subjects in the universe. Again, it might act upon other things besides number, were objects found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine... Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent. • Ada, Countess of Lovelace, around 1830 CS 201J Fall 2002

  12. What is the difference between Euclid and Ada? “It depends on what your definition of ‘is’ is.” Bill Gates (at Microsoft’s anti- trust trial) CS 201J Fall 2002

  13. Geometry vs. Computer Science • Geometry (mathematics) is about declarative knowledge: “what is” If now CD measures AB, since it also measures itself, then CDis a common measure of CD and AB • Computer Science is about imperative knowledge: “how to” Computer Science has nothing to do with beige (or translucent blue) boxes called “computers” and is not a science. CS 201J Fall 2002

  14. Computer Science “How to” knowledge: • Ways of describing and carrying out imperative processes (computations) • Ways of reasoning about (predicting) what imperative processes will do About 50% of CS201J is about these things… but nearly all of CS200 is! CS 201J Fall 2002

  15. Spring 2003 CS200: Computer Science From Ada and Euclid to Quantum Computers and the World Wide Web www.cs.virginia.edu/cs200 Meetings: Mondays, Wednesdays and Fridays at 2:00-2:50 pm CS201J graduates can take (SEAS tech elective credit), but no prior background is expected. CS 201J Fall 2002

  16. How to never lose at Tic-Tac-Toe CS 201J Fall 2002

  17. Tic-Tac-Toe X O X X O O X CS 201J Fall 2002

  18. Tic-Tac-Toe Game Tree X O 3 2 1 X X O 1 2 3 4 5 6 X O X X X … 7 8 9 X 2 3 X O CS 201J Fall 2002

  19. Playing Tic-Tac-Toe • Goal: get three of your marks in a line before your opponent does • Sub-goal: get to a position where it is your move, and you have a line with 2 of your marks and one empty square • Sub2-goal: get to a position where it is your opponent’s move, and no matter what she does, after her move sub1-goal is satisfied • Sub3-goal: get to a position where it is your move, and you can make a move that satisfies sub2-goal is satisfied • Sub4-goal: get to a position where it is your opponent’s move, and no matter what she does, after her move sub3-goal is satisfied • … • Subn-goal: from the start, get to a position where no matter how your opponent moves, you can select moves that get to the Goal CS 201J Fall 2002

  20. Minimax • Evaluate a game situation based on how good it is for you • Try to maximize your score, assuming opponent will try to minimize your score (that is, maximize her score) • Score (tic-tac-toe board) = • -1 if opponent has 3 in line • 0 if neither has 3 in line • 1 if I have 3 in line CS 201J Fall 2002

  21. Minimax Tic-Tac • Score (tic-tac board) = • -1 if opponent has 2 in vertical line • 0 if neither has 2 in vertical line • 1 if I have 2 in vertical line 1 Max: 0 2 3 4 X X Score (b) = 0 0 0 X 0 X Min: 0 3 4 2 O X X X O O Score (b) = 1 0 1 Max: 0 Max: 1 2 4 3 4 X X X O O X X O X O X X Score (b) = 1 0 0 0 CS 201J Fall 2002

  22. Why is there no international tic-tac-toe championship? • Total tic-tac-toe games to try = 9 * 8 * 7 * 6 * … * 1 = 9! = 362 880 • Minimax tells you that if both players pick the best move, it is always a draw • What about chess? • ~101050 possible chess games • After 4 moves, there are (at least) 809 896 possible positions! CS 201J Fall 2002

  23. Deep Blue (1997) • Evaluates 400m moves/second • Need complex scoring functions for positions • Special purpose hardware for scoring chess positions quickly • Database of openings, special situations, etc. CS 201J Fall 2002

  24. Networking CS 201J Fall 2002

  25. PS7 Networking int port = …; Server Socket ss = new ServerSocket (port); ServerSocket listens to network port for incoming connections… Snakes Server Socket client = ss.accept (); A Socket gives you an input and output stream abstraction for dealing with network communication. CS 201J Fall 2002

  26. Snakes Client import java.io.*; import java.net.*; public class MySnake extends SnakeInterface { private ClientDisplay display; private final int FRAME_WIDTH = 400; private final int FRAME_HEIGHT = 400; public MySnake (Socket s) throws IOException { super (s); … // set up the display } // The SnakeInterface run method will call this whenever the state of // the world has changed. public void updateState () { if (display != null) { display.updateGrid (); } } CS 201J Fall 2002

  27. MySnake main static public void main (String args[]) { if (args.length != 2) { System.err.println ("Usage: java MySnake <server> <port>"); System.exit (1); } else { String server = args [0]; int port = Integer.valueOf (args[1]).intValue (); try { Socket s = new Socket (server, port); MySnake ms = new MySnake (s); } catch … { // Need to catch exceptions if server is not reachable } } } Hint: You will want to do something similar in your PS7 code! CS 201J Fall 2002

  28. Who Invented the Internet? CS 201J Fall 2002

  29. Who Invented Networking? CS 201J Fall 2002

  30. What is a Network? A group of three or more connected communicating entities CS 201J Fall 2002

  31. Beacon Chain Networking Thus, from some far-away beleaguered island, where all day long the men have fought a desperate battle from their city walls, the smoke goes up to heaven; but no sooner has the sun gone down than the light from the line of beacons blazes up and shoots into the sky to warn the neighbouring islanders and bring them to the rescue in their ships. Iliad, Homer, 700 BC Chain of beacon’s signaled Agammemnon’s return (~1200BC), spread on Greek peaks over 600km. CS 201J Fall 2002

  32. Chappe’s Semaphore Network First Line (Paris to Lille), 1794 Mobile Semaphore TelegraphUsed in the Crimean War 1853-1856 CS 201J Fall 2002

  33. Measuring Networks • Latency Time from sending a bit until it arrives seconds (or seconds per geographic distance) • Bandwidth How much information can you transmit per time unit bits per second CS 201J Fall 2002

  34. Latency and Bandwidth • Napoleon’s Network (Paris to Toulon, 475 miles) • Latency: 13 minutes (1.6s per mile) • What is the delay at each signaling station, how many stations to reach destination • At this rate, it would take ~1 hour to get a bit from California • Bandwidth: 2 symbols per minute (98 possible symbols, so that is ~13 bits per minute • How fast can signalers make symbols • At this rate, it would take you 3 ½ years to download today’s slides! CS 201J Fall 2002

  35. Improving Latency • Less transfer points • Longer distances between transfer points • Semaphores: how far can you see clearly • Telescopes can help, but curvature of Earth is hard to overcome • Use wires (electrical telegraphs, 1837) • Faster travel • Hard to beat speed of light (semaphore network) • Electrons in copper travel about 1/3rd speed of light • Faster transfers • Replace humans with machines CS 201J Fall 2002

  36. Improving Bandwidth • Faster transmission • Train signalers to move semaphore flags faster • Use something less physically demanding to transmit • Bigger pipes • Have multiple signalers transmit every other letter at the same time • Better encoding • Figure out how to code more than 98 symbols with semaphore signal • Morse code (1840s) CS 201J Fall 2002

  37. internetwork A collection of multiple networks connected together, so messages can be transmitted between nodes on different networks. CS 201J Fall 2002

  38. Okay, so who invented the Internet? CS 201J Fall 2002

  39. The First Internet • 1800: Sweden and Denmark worried about Britain invading • Edelcrantz proposes link across strait separating Sweden and Denmark to connect their (signaling) telegraph networks • 1801: British attack Copenhagen, network transmit message to Sweden, but they don’t help. • Denmark signs treaty with Britain, and stops communications with Sweden CS 201J Fall 2002

  40. First Use of Internet • October 1969: First packets on the ARPANet from UCLA to Stanford. Starts to send "LOGIN", but it crashes on the G. • 20 July 1969: Live video (b/w) and audio transmitted from moon to Earth, and to several hundred televisions worldwide. CS 201J Fall 2002

  41. The Modern Internet • Packet Switching: Leonard Kleinrock (UCLA) thinks he did, Donald Davies and Paul Baran, Edelcrantz’s signalling network (1809) sort of did it • Internet Protocol: Vint Cerf, Bob Kahn • Vision, Funding: J.C.R. Licklider, Bob Taylor • Government: Al Gore (first politician to promote Internet, 1986; act to connect government networks to form “Interagency Network”) CS 201J Fall 2002

  42. Charge • PS7 is due week from tomorrow! • New ps7.zip will be available later today: • Grid that uses cartesian coordinates • Better server • Small changes to SnakeInterface • If you have made enough progress that any of these changes cause problems, email me for restitution. • Enjoy your Thanksgiving! • Remember if you eat too many apples, you will grow and it will be harder to avoid running into your tail! CS 201J Fall 2002

More Related