Commits

Jacek Bzdak committed 581194b

...

Comments (0)

Files changed (11)

pojava-interferen/2d.png

Added
New image

pojava-interferen/2dx.png

Added
New image

pojava-interferen/2dy.png

Added
New image

pojava-interferen/3d.png

Added
New image

pojava-interferen/interference.py

+__author__ = 'jb'
+
+import matplotlib
+matplotlib.use('Qt4Agg')
+import sys
+import numpy as np
+import math
+import matplotlib.pyplot as plt
+
+ARRAY_SHAPE = (1000, 1000)
+ARRAY_SCALE = (100.0, 100.0)
+array = np.zeros(ARRAY_SHAPE)
+
+SOURCE_POSITIONS = (
+    (0, 0),
+    (100, 0),
+    (200, 0),
+    (300, 0),
+    (400, 0),
+    (500, 0),
+    (600, 0),
+    (700, 0),
+    (800, 0),
+    (900, 0),
+    (1000, 0),
+)
+
+for ii in range(ARRAY_SHAPE[0]):
+    for jj in range(ARRAY_SHAPE[1]):
+        for ii_diff, jj_diff in SOURCE_POSITIONS:
+            # array[ii, jj] = math.sin(math.pow((ii*ii+ jj*jj) / ARRAY_SCALE[0], 0.5))
+            ii_moved = ii - ii_diff
+            jj_moved = jj - jj_diff
+            array[ii, jj] += math.sin(math.pow((ii_moved*ii_moved/ARRAY_SCALE[0]+ jj_moved*jj_moved/ARRAY_SCALE[1]), 0.5))
+
+array*=array
+
+plt.ion()
+
+plt.imshow(array)
+plt.colorbar()
+
+plt.savefig('3d.png')
+plt.clf()
+plt.plot(array[500, :])
+plt.savefig('2dx.png')
+plt.clf()
+plt.plot(array[:, 500])
+plt.savefig('2dy.png')
+
+#
+# for line in sys.stdin:
+#     print line

pojava-interferen/temp.png

Added
New image

sk/src/pl/edu/pw/fizyka/sk/example/ClientSocket.java

 package pl.edu.pw.fizyka.sk.example;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintWriter;
+import java.io.*;
 import java.net.Socket;
 
 public class ClientSocket {
     public static void main(String[] args) throws Exception{
         Socket socket = new Socket("lfitj.if.pw.edu.pl", 80);
-        OutputStream outputStream = socket.getOutputStream();
-        PrintWriter printWriter = new PrintWriter(outputStream);
-        printWriter.print("GET /dydaktyka/sk/zaj2.html HTTP/1.0\n\n");
-        printWriter.flush();
+        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
+        bufferedWriter.write("GET /dydaktyka/sk/zaj2.html HTTP/1.0\n\n");
+        bufferedWriter.flush();
         BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
         String line = reader.readLine();
         while (line!=null){

sk/src/pl/edu/pw/fizyka/sk/example/MultihreadedServerSocketExample.java

                         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                         BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                         bufferedWriter.write("Napisz: \"END\" by zakończyć połączenie.");
+                        bufferedWriter.flush();
                         String line = bufferedReader.readLine();
                         while (!line.contains("END")){
                             bufferedWriter.write("Sever says: ");
                         }
                         socket.close();
                     } catch (IOException e) {
-                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                        e.printStackTrace();
                     }
 
                 }

sk/src/pl/edu/pw/fizyka/sk/example/ServerSocketExample.java

             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
             BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
             bufferedWriter.write("Napisz: \"END\" by zakończyć połączenie.");
+            bufferedWriter.flush();
             String line = bufferedReader.readLine();
             while (!line.contains("END")){
                 bufferedWriter.write("Sever says: ");

sk/src/pl/edu/pw/fizyka/sk/tictactoe/api/Board.java

 
 
 
-import java.io.OutputStream;
-import java.io.PrintStream;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
         }
     }
 
+    public static void print(Writer writer, State[] board) throws IOException{
+        if (board.length !=9){
+            throw new IllegalStateException("Board.length must be equal to 9.");
+        }
+
+        BufferedWriter bufferedWriter;
+        if (writer instanceof BufferedWriter){
+            bufferedWriter = (BufferedWriter) writer;
+        }else{
+            bufferedWriter = new BufferedWriter(writer);
+        }
+
+        for (int ii = 0;  ii < 3; ii++){
+            for(int jj = 0; jj < 3; jj++){
+                int index = ii * 3 + jj;
+                bufferedWriter.write(State.label(board[index], index));
+                if (jj <2){
+                    bufferedWriter.write("|");
+                }
+            }
+            bufferedWriter.write("\n");
+        }
+
+        bufferedWriter.flush();
+    }
+
     public static boolean legalMove(State[] board, int index){
         return board[index] == null;
     }

sk/src/pl/edu/pw/fizyka/sk/tictactoe/solution/AiConsoleGameSimple.java

+package pl.edu.pw.fizyka.sk.tictactoe.solution;
+
+import pl.edu.pw.fizyka.sk.tictactoe.api.AiPlayer;
+import pl.edu.pw.fizyka.sk.tictactoe.api.Board;
+import pl.edu.pw.fizyka.sk.tictactoe.api.Player;
+import pl.edu.pw.fizyka.sk.tictactoe.api.State;
+
+import java.io.*;
+
+public class AiConsoleGameSimple {
+
+    public static void main(String[] args) throws IOException {
+        Player aiPlayer = new AiPlayer();
+        aiPlayer.setSymbol(State.X);
+
+        Board board = new Board();
+
+        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //Opakowanie standardowego wejścia
+        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); //Opakowanie standardowego wyjścia
+
+        while (board.getLegalMoves().size()>0){
+
+            bufferedWriter.write("Plansza:\n");
+            Board.print(bufferedWriter, board.getBoard());
+            bufferedWriter.write("Twój ruch:\n");
+            bufferedWriter.flush();
+
+            String line = bufferedReader.readLine();
+
+            board.play(Integer.parseInt(line), State.O);
+
+            if (board.winner() != null){
+                bufferedWriter.write("Wygrał: " + board.winner());
+                bufferedWriter.write("Plansza:\n");
+                Board.print(bufferedWriter, board.getBoard());
+                return;
+            }
+
+            board.play(aiPlayer.nextMove(board.getBoard()), State.X);
+
+            if (board.winner() != null){
+                bufferedWriter.write("Wygrał: " + board.winner());
+                bufferedWriter.write("Plansza:\n");
+                Board.print(bufferedWriter, board.getBoard());
+                return;
+            }
+
+        }
+
+    }
+}