commit 439f8e6f1ad6a277c593c274803826b6281f4041 Author: erius Date: Fri Aug 18 01:08:53 2023 +0300 Initital commit diff --git a/sem2/print_hex b/sem2/print_hex new file mode 100644 index 0000000..d8288f4 Binary files /dev/null and b/sem2/print_hex differ diff --git a/sem2/print_hex.asm b/sem2/print_hex.asm new file mode 100644 index 0000000..a309842 --- /dev/null +++ b/sem2/print_hex.asm @@ -0,0 +1,26 @@ +section .data + +codes: db '0123456789ABCDEF' + +section .text + +global print_hex +print_hex: + mov rdi, 1 + mov rdx, 1 + mov rcx, 64 + .loop: + push rax + sub rcx, 4 + sar rax, cl + and rax, 0xf + lea rsi, [codes + rax] + mov rax, 1 + push rcx + syscall + pop rcx + pop rax + test rcx, rcx + jnz .loop + ret + diff --git a/sem2/print_hex.o b/sem2/print_hex.o new file mode 100644 index 0000000..904d5f6 Binary files /dev/null and b/sem2/print_hex.o differ diff --git a/sem3/task-custom-make/Lab2-1.0.jar b/sem3/task-custom-make/Lab2-1.0.jar new file mode 100644 index 0000000..61baced Binary files /dev/null and b/sem3/task-custom-make/Lab2-1.0.jar differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/executionHistory/executionHistory.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/executionHistory/executionHistory.bin new file mode 100644 index 0000000..a5ebd98 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/executionHistory/executionHistory.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/executionHistory/executionHistory.lock b/sem3/task-custom-make/Lab2/.gradle/5.6.3/executionHistory/executionHistory.lock new file mode 100644 index 0000000..4bbc67f Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/executionHistory/executionHistory.lock differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileChanges/last-build.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileChanges/last-build.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileContent/fileContent.lock b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileContent/fileContent.lock new file mode 100644 index 0000000..9d986c3 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileContent/fileContent.lock differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/fileHashes.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/fileHashes.bin new file mode 100644 index 0000000..8cd4655 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/fileHashes.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/fileHashes.lock b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/fileHashes.lock new file mode 100644 index 0000000..7ae65be Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/fileHashes.lock differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/resourceHashesCache.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..d9a1a26 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/fileHashes/resourceHashesCache.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/gc.properties b/sem3/task-custom-make/Lab2/.gradle/5.6.3/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/classAnalysis.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/classAnalysis.bin new file mode 100644 index 0000000..0c84d12 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/classAnalysis.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/jarAnalysis.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/jarAnalysis.bin new file mode 100644 index 0000000..e3d7f55 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/jarAnalysis.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/javaCompile.lock b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/javaCompile.lock new file mode 100644 index 0000000..9f9be19 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/javaCompile.lock differ diff --git a/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/taskHistory.bin b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/taskHistory.bin new file mode 100644 index 0000000..2e86cdb Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/5.6.3/javaCompile/taskHistory.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..e3cf4a3 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/cache.properties b/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..7c03b14 --- /dev/null +++ b/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Wed Sep 29 20:58:54 MSK 2021 +gradle.version=5.6.3 diff --git a/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/outputFiles.bin b/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..d5eab0b Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/sem3/task-custom-make/Lab2/.gradle/checksums/checksums.lock b/sem3/task-custom-make/Lab2/.gradle/checksums/checksums.lock new file mode 100644 index 0000000..f5dba26 Binary files /dev/null and b/sem3/task-custom-make/Lab2/.gradle/checksums/checksums.lock differ diff --git a/sem3/task-custom-make/Lab2/.gradle/vcs-1/gc.properties b/sem3/task-custom-make/Lab2/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/sem3/task-custom-make/Lab2/.idea/.gitignore b/sem3/task-custom-make/Lab2/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/sem3/task-custom-make/Lab2/.idea/compiler.xml b/sem3/task-custom-make/Lab2/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/discord.xml b/sem3/task-custom-make/Lab2/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/encodings.xml b/sem3/task-custom-make/Lab2/.idea/encodings.xml new file mode 100644 index 0000000..4973c61 --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/gradle.xml b/sem3/task-custom-make/Lab2/.idea/gradle.xml new file mode 100644 index 0000000..611e7c8 --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/jarRepositories.xml b/sem3/task-custom-make/Lab2/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/misc.xml b/sem3/task-custom-make/Lab2/.idea/misc.xml new file mode 100644 index 0000000..2266f6b --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/runConfigurations.xml b/sem3/task-custom-make/Lab2/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/.idea/uiDesigner.xml b/sem3/task-custom-make/Lab2/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/sem3/task-custom-make/Lab2/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sem3/task-custom-make/Lab2/build.gradle b/sem3/task-custom-make/Lab2/build.gradle new file mode 100644 index 0000000..5600845 --- /dev/null +++ b/sem3/task-custom-make/Lab2/build.gradle @@ -0,0 +1,28 @@ +plugins { + id 'java' +} + +group 'ru.erius' +version '1.0' +def pokemon = files('libs/Pokemon.jar') +def main_class = group + '.lab2.Lab2' + +dependencies { + implementation pokemon +} + +jar { + manifest { + attributes 'Manifest-Version': '1.0', 'Main-Class': main_class + } + + from { + configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } + } +} + +compileJava.options.encoding = 'UTF-8' + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} diff --git a/sem3/task-custom-make/Lab2/build/classes/java/main/ru/erius/lab2/Lab2.class b/sem3/task-custom-make/Lab2/build/classes/java/main/ru/erius/lab2/Lab2.class new file mode 100644 index 0000000..46b70f6 Binary files /dev/null and b/sem3/task-custom-make/Lab2/build/classes/java/main/ru/erius/lab2/Lab2.class differ diff --git a/sem3/task-custom-make/Lab2/gradlew b/sem3/task-custom-make/Lab2/gradlew new file mode 100644 index 0000000..744e882 --- /dev/null +++ b/sem3/task-custom-make/Lab2/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MSYS* | MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/sem3/task-custom-make/Lab2/gradlew.bat b/sem3/task-custom-make/Lab2/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/sem3/task-custom-make/Lab2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/sem3/task-custom-make/Lab2/settings.gradle b/sem3/task-custom-make/Lab2/settings.gradle new file mode 100644 index 0000000..b0a4264 --- /dev/null +++ b/sem3/task-custom-make/Lab2/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'Lab2' + diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/Lab2.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/Lab2.java new file mode 100644 index 0000000..2ea4915 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/Lab2.java @@ -0,0 +1,32 @@ +package ru.erius.lab2; + +import ru.erius.lab2.pokemon.*; +import ru.ifmo.se.pokemon.Battle; +import ru.ifmo.se.pokemon.Pokemon; + +import java.util.Arrays; +import java.util.List; + +public class Lab2 { + + public static void main(String[] args) { + List allies = Arrays.asList( + new Comfey("Лёха", 1), + new Gligar("Олег", 1), + new Gliscor("Акакий", 1) + ); + List foes = Arrays.asList( + new Torchic("Гоша", 1), + new Combusken("Николай", 1), + new Blaziken("Владимир", 1) + ); + Battle battle = new Battle(); + allies.forEach(battle::addAlly); + foes.forEach(battle::addFoe); + battle.go(); + } + + private static int randLvl() { + return (int) (Math.random() * 99.0D + 1.0D); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/physical/Bulldoze.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/physical/Bulldoze.java new file mode 100644 index 0000000..1f8e6b1 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/physical/Bulldoze.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.physical; + +import ru.ifmo.se.pokemon.*; + +public class Bulldoze extends PhysicalMove { + + private final static String NAME = "Bulldoze"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.GROUND; + private final static double POWER = 60.0D, ACCURACY = 100.0D; + + public Bulldoze() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.SPEED, -1); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/physical/Facade.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/physical/Facade.java new file mode 100644 index 0000000..5b2258b --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/physical/Facade.java @@ -0,0 +1,28 @@ +package ru.erius.lab2.move.physical; + +import ru.ifmo.se.pokemon.*; + +public class Facade extends PhysicalMove { + + private final static String NAME = "Facade"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 70.0D, ACCURACY = 100.0D; + + public Facade() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected double calcBaseDamage(Pokemon pokemon, Pokemon pokemon1) { + Status status = pokemon.getCondition(); + boolean hasRequiredStatus = status == Status.BURN || status == Status.POISON || status == Status.PARALYZE; + int multiplier = hasRequiredStatus ? 2 : 1; + return super.calcBaseDamage(pokemon, pokemon1) * multiplier; + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/special/AirSlash.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/special/AirSlash.java new file mode 100644 index 0000000..c99c703 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/special/AirSlash.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.special; + +import ru.ifmo.se.pokemon.*; + +public class AirSlash extends SpecialMove { + + private final static String NAME = "Air Slash"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.FLYING; + private final static double POWER = 75.0D, ACCURACY = 95.0D; + + public AirSlash() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + if (Math.random() < 0.3D) Effect.flinch(pokemon); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/AquaRing.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/AquaRing.java new file mode 100644 index 0000000..7c5a533 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/AquaRing.java @@ -0,0 +1,27 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class AquaRing extends StatusMove { + + private final static String NAME = "Aqua Ring"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.WATER; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public AquaRing() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applySelfEffects(Pokemon pokemon) { + double maxHP = pokemon.getStat(Stat.HP); + Effect waterVeil = new Effect().stat(Stat.HP, (int) -(maxHP/ 16)).turns(-1); + pokemon.addEffect(waterVeil); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Confide.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Confide.java new file mode 100644 index 0000000..ba68e00 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Confide.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Confide extends StatusMove { + + private final static String NAME = "Confide"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public Confide() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.SPECIAL_ATTACK, -1); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/DoubleTeam.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/DoubleTeam.java new file mode 100644 index 0000000..a9e229f --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/DoubleTeam.java @@ -0,0 +1,28 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Stat; +import ru.ifmo.se.pokemon.StatusMove; +import ru.ifmo.se.pokemon.Type; + +public class DoubleTeam extends StatusMove { + + private final static String NAME = "Double Team"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public DoubleTeam() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applySelfEffects(Pokemon pokemon) { + pokemon.setMod(Stat.EVASION, 1); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Leer.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Leer.java new file mode 100644 index 0000000..960dbc6 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Leer.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Leer extends StatusMove { + + private final static String NAME = "Leer"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public Leer() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.DEFENSE, -1); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Rest.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Rest.java new file mode 100644 index 0000000..0201d56 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Rest.java @@ -0,0 +1,30 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Rest extends StatusMove { + + private final static String NAME = "Rest"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.PSYCHIC; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + private final static Effect SLEEP = new Effect().condition(Status.SLEEP).turns(2); + + public Rest() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applySelfEffects(Pokemon pokemon) { + double maxHP = pokemon.getStat(Stat.HP); + double heal = maxHP - pokemon.getHP(); + pokemon.setMod(Stat.HP, (int) -heal); + pokemon.addEffect(SLEEP); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Supersonic.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Supersonic.java new file mode 100644 index 0000000..bb8c2cf --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Supersonic.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Supersonic extends StatusMove { + + private final static String NAME = "Supersonic"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 55.0D; + + public Supersonic() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + Effect.confuse(pokemon); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Swagger.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Swagger.java new file mode 100644 index 0000000..31fe6cc --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/move/status/Swagger.java @@ -0,0 +1,26 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Swagger extends StatusMove { + + private final static String NAME = "Swagger"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 85.0D; + + public Swagger() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.ATTACK, 1); + Effect.confuse(pokemon); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Blaziken.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Blaziken.java new file mode 100644 index 0000000..058d3e3 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Blaziken.java @@ -0,0 +1,33 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Swagger; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Type; + +import java.util.Collections; +import java.util.List; + +public class Blaziken extends Combusken { + + protected final static String NAME = "Blaziken"; + protected final static List TYPES = Collections.emptyList(); + protected final static double + HP = 60.0D, ATTACK = 85.0D, DEFENSE = 60.0D, + SP_ATK = 85.0D, SP_DEF = 60.0D, SPEED = 55.0D; + protected final static List MOVES = Collections.singletonList(new Swagger()); + + public Blaziken(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Blaziken(int lvl) { + super(lvl); + } + + public Blaziken() { + super(); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Combusken.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Combusken.java new file mode 100644 index 0000000..c65c1aa --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Combusken.java @@ -0,0 +1,33 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Supersonic; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Type; + +import java.util.Collections; +import java.util.List; + +public class Combusken extends Torchic { + + protected final static String NAME = "Combusken"; + protected final static List TYPES = Collections.singletonList(Type.FIGHTING); + protected final static double + HP = 60.0D, ATTACK = 85.0D, DEFENSE = 60.0D, + SP_ATK = 85.0D, SP_DEF = 60.0D, SPEED = 55.0D; + protected final static List MOVES = Collections.singletonList(new Supersonic()); + + public Combusken(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Combusken(int lvl) { + super(lvl); + } + + public Combusken() { + super(); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Comfey.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Comfey.java new file mode 100644 index 0000000..ef68ef1 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Comfey.java @@ -0,0 +1,38 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.physical.Bulldoze; +import ru.erius.lab2.move.special.AirSlash; +import ru.erius.lab2.move.status.AquaRing; +import ru.erius.lab2.move.status.Swagger; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Type; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class Comfey extends Pokemon { + + protected final static String NAME = "Comfey"; + protected final static List TYPES = Collections.singletonList(Type.FAIRY); + protected final static double + HP = 51.0D, ATTACK = 52.0D, DEFENSE = 90.0D, + SP_ATK = 82.0D, SP_DEF = 110.0D, SPEED = 100.0D; + protected final static List MOVES = Arrays.asList(new AirSlash(), new AquaRing(), new Swagger(), new Bulldoze()); + + public Comfey(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Comfey(int lvl) { + this(NAME, lvl); + } + + public Comfey() { + this(NAME, 1); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Gligar.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Gligar.java new file mode 100644 index 0000000..2c677c6 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Gligar.java @@ -0,0 +1,36 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Confide; +import ru.erius.lab2.move.physical.Facade; +import ru.erius.lab2.move.status.Swagger; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Type; + +import java.util.Arrays; +import java.util.List; + +public class Gligar extends Pokemon { + + protected final static String NAME = "Gligar"; + protected final static List TYPES = Arrays.asList(Type.GROUND, Type.FLYING); + protected final static double + HP = 65.0D, ATTACK = 75.0D, DEFENSE = 105.0D, + SP_ATK = 35.0D, SP_DEF = 65.0D, SPEED = 85.0D; + protected final static List MOVES = Arrays.asList(new Swagger(), new Confide(), new Facade()); + + public Gligar(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Gligar(int lvl) { + this(NAME, lvl); + } + + public Gligar() { + this(NAME, 1); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Gliscor.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Gliscor.java new file mode 100644 index 0000000..ea12427 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Gliscor.java @@ -0,0 +1,33 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Leer; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Type; + +import java.util.Collections; +import java.util.List; + +public class Gliscor extends Gligar { + + protected final static String NAME = "Gliscor"; + protected final static List TYPES = Collections.emptyList(); + protected final static double + HP = 75.0D, ATTACK = 95.0D, DEFENSE = 125.0D, + SP_ATK = 45.0D, SP_DEF = 75.0D, SPEED = 95.0D; + protected final static List MOVES = Collections.singletonList(new Leer()); + + public Gliscor(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Gliscor(int lvl) { + super(lvl); + } + + public Gliscor() { + super(); + } +} diff --git a/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Torchic.java b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Torchic.java new file mode 100644 index 0000000..f914946 --- /dev/null +++ b/sem3/task-custom-make/Lab2/src/main/java/ru/erius/lab2/pokemon/Torchic.java @@ -0,0 +1,34 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.DoubleTeam; +import ru.erius.lab2.move.status.Rest; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Type; + +import java.util.*; + +public class Torchic extends Pokemon { + + protected final static String NAME = "Torchic"; + protected final static List TYPES = Collections.singletonList(Type.FIRE); + protected final static double + HP = 45.0D, ATTACK = 60.0D, DEFENSE = 40.0D, + SP_ATK = 70.0D, SP_DEF = 50.0D, SPEED = 45.0D; + protected final static List MOVES = Arrays.asList(new DoubleTeam(), new Rest()); + + public Torchic(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Torchic(int lvl) { + this(NAME, lvl); + } + + public Torchic() { + this(NAME, 1); + } +} diff --git a/sem3/task-custom-make/lab2_prog.docx b/sem3/task-custom-make/lab2_prog.docx new file mode 100644 index 0000000..da39c7b Binary files /dev/null and b/sem3/task-custom-make/lab2_prog.docx differ diff --git a/sem3/task-custom-make/makefile b/sem3/task-custom-make/makefile new file mode 100644 index 0000000..e69de29 diff --git a/sem3/task-custom-make/task/Pokemon.jar b/sem3/task-custom-make/task/Pokemon.jar new file mode 100644 index 0000000..3208b36 Binary files /dev/null and b/sem3/task-custom-make/task/Pokemon.jar differ diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/Lab2.java b/sem3/task-custom-make/task/code/ru/erius/lab2/Lab2.java new file mode 100644 index 0000000..86991a7 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/Lab2.java @@ -0,0 +1,33 @@ +package ru.erius.lab2; + +import ru.erius.lab2.pokemon.*; +import ru.ifmo.se.pokemon.Battle; +import ru.ifmo.se.pokemon.Pokemon; + +import java.util.Arrays; +import java.util.List; + +public class Lab2 { + + public static void main(String[] args) { + System.out.println("test"); + List allies = Arrays.asList( + new Comfey("Лёха", 1), + new Gligar("Олег", 1), + new Gliscor("Акакий", 1) + ); + List foes = Arrays.asList( + new Torchic("Гоша", 1), + new Combusken("Николай", 1), + new Blaziken("Владимир", 1) + ); + Battle battle = new Battle(); + allies.forEach(battle::addAlly); + foes.forEach(battle::addFoe); + battle.go(); + } + + private static int randLvl() { + return (int) (Math.random() * 99.0D + 1.0D); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/physical/Bulldoze.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/physical/Bulldoze.java new file mode 100644 index 0000000..1f8e6b1 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/physical/Bulldoze.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.physical; + +import ru.ifmo.se.pokemon.*; + +public class Bulldoze extends PhysicalMove { + + private final static String NAME = "Bulldoze"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.GROUND; + private final static double POWER = 60.0D, ACCURACY = 100.0D; + + public Bulldoze() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.SPEED, -1); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/physical/Facade.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/physical/Facade.java new file mode 100644 index 0000000..5b2258b --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/physical/Facade.java @@ -0,0 +1,28 @@ +package ru.erius.lab2.move.physical; + +import ru.ifmo.se.pokemon.*; + +public class Facade extends PhysicalMove { + + private final static String NAME = "Facade"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 70.0D, ACCURACY = 100.0D; + + public Facade() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected double calcBaseDamage(Pokemon pokemon, Pokemon pokemon1) { + Status status = pokemon.getCondition(); + boolean hasRequiredStatus = status == Status.BURN || status == Status.POISON || status == Status.PARALYZE; + int multiplier = hasRequiredStatus ? 2 : 1; + return super.calcBaseDamage(pokemon, pokemon1) * multiplier; + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/special/AirSlash.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/special/AirSlash.java new file mode 100644 index 0000000..c99c703 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/special/AirSlash.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.special; + +import ru.ifmo.se.pokemon.*; + +public class AirSlash extends SpecialMove { + + private final static String NAME = "Air Slash"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.FLYING; + private final static double POWER = 75.0D, ACCURACY = 95.0D; + + public AirSlash() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + if (Math.random() < 0.3D) Effect.flinch(pokemon); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/AquaRing.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/AquaRing.java new file mode 100644 index 0000000..7c5a533 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/AquaRing.java @@ -0,0 +1,27 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class AquaRing extends StatusMove { + + private final static String NAME = "Aqua Ring"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.WATER; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public AquaRing() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applySelfEffects(Pokemon pokemon) { + double maxHP = pokemon.getStat(Stat.HP); + Effect waterVeil = new Effect().stat(Stat.HP, (int) -(maxHP/ 16)).turns(-1); + pokemon.addEffect(waterVeil); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Confide.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Confide.java new file mode 100644 index 0000000..ba68e00 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Confide.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Confide extends StatusMove { + + private final static String NAME = "Confide"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public Confide() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.SPECIAL_ATTACK, -1); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/DoubleTeam.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/DoubleTeam.java new file mode 100644 index 0000000..a9e229f --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/DoubleTeam.java @@ -0,0 +1,28 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Stat; +import ru.ifmo.se.pokemon.StatusMove; +import ru.ifmo.se.pokemon.Type; + +public class DoubleTeam extends StatusMove { + + private final static String NAME = "Double Team"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public DoubleTeam() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applySelfEffects(Pokemon pokemon) { + pokemon.setMod(Stat.EVASION, 1); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Leer.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Leer.java new file mode 100644 index 0000000..960dbc6 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Leer.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Leer extends StatusMove { + + private final static String NAME = "Leer"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + public Leer() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.DEFENSE, -1); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Rest.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Rest.java new file mode 100644 index 0000000..0201d56 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Rest.java @@ -0,0 +1,30 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Rest extends StatusMove { + + private final static String NAME = "Rest"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.PSYCHIC; + private final static double POWER = 0.0D, ACCURACY = 100.0D; + + private final static Effect SLEEP = new Effect().condition(Status.SLEEP).turns(2); + + public Rest() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applySelfEffects(Pokemon pokemon) { + double maxHP = pokemon.getStat(Stat.HP); + double heal = maxHP - pokemon.getHP(); + pokemon.setMod(Stat.HP, (int) -heal); + pokemon.addEffect(SLEEP); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Supersonic.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Supersonic.java new file mode 100644 index 0000000..bb8c2cf --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Supersonic.java @@ -0,0 +1,25 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Supersonic extends StatusMove { + + private final static String NAME = "Supersonic"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 55.0D; + + public Supersonic() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + Effect.confuse(pokemon); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Swagger.java b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Swagger.java new file mode 100644 index 0000000..31fe6cc --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/move/status/Swagger.java @@ -0,0 +1,26 @@ +package ru.erius.lab2.move.status; + +import ru.ifmo.se.pokemon.*; + +public class Swagger extends StatusMove { + + private final static String NAME = "Swagger"; + private final static String MESSAGE = "использует " + NAME; + private final static Type TYPE = Type.NORMAL; + private final static double POWER = 0.0D, ACCURACY = 85.0D; + + public Swagger() { + super(TYPE, POWER, ACCURACY); + } + + @Override + protected String describe() { + return MESSAGE; + } + + @Override + protected void applyOppEffects(Pokemon pokemon) { + pokemon.setMod(Stat.ATTACK, 1); + Effect.confuse(pokemon); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Blaziken.java b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Blaziken.java new file mode 100644 index 0000000..058d3e3 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Blaziken.java @@ -0,0 +1,33 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Swagger; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Type; + +import java.util.Collections; +import java.util.List; + +public class Blaziken extends Combusken { + + protected final static String NAME = "Blaziken"; + protected final static List TYPES = Collections.emptyList(); + protected final static double + HP = 60.0D, ATTACK = 85.0D, DEFENSE = 60.0D, + SP_ATK = 85.0D, SP_DEF = 60.0D, SPEED = 55.0D; + protected final static List MOVES = Collections.singletonList(new Swagger()); + + public Blaziken(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Blaziken(int lvl) { + super(lvl); + } + + public Blaziken() { + super(); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Combusken.java b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Combusken.java new file mode 100644 index 0000000..c65c1aa --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Combusken.java @@ -0,0 +1,33 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Supersonic; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Type; + +import java.util.Collections; +import java.util.List; + +public class Combusken extends Torchic { + + protected final static String NAME = "Combusken"; + protected final static List TYPES = Collections.singletonList(Type.FIGHTING); + protected final static double + HP = 60.0D, ATTACK = 85.0D, DEFENSE = 60.0D, + SP_ATK = 85.0D, SP_DEF = 60.0D, SPEED = 55.0D; + protected final static List MOVES = Collections.singletonList(new Supersonic()); + + public Combusken(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Combusken(int lvl) { + super(lvl); + } + + public Combusken() { + super(); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Comfey.java b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Comfey.java new file mode 100644 index 0000000..ef68ef1 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Comfey.java @@ -0,0 +1,38 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.physical.Bulldoze; +import ru.erius.lab2.move.special.AirSlash; +import ru.erius.lab2.move.status.AquaRing; +import ru.erius.lab2.move.status.Swagger; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Type; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class Comfey extends Pokemon { + + protected final static String NAME = "Comfey"; + protected final static List TYPES = Collections.singletonList(Type.FAIRY); + protected final static double + HP = 51.0D, ATTACK = 52.0D, DEFENSE = 90.0D, + SP_ATK = 82.0D, SP_DEF = 110.0D, SPEED = 100.0D; + protected final static List MOVES = Arrays.asList(new AirSlash(), new AquaRing(), new Swagger(), new Bulldoze()); + + public Comfey(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Comfey(int lvl) { + this(NAME, lvl); + } + + public Comfey() { + this(NAME, 1); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Gligar.java b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Gligar.java new file mode 100644 index 0000000..2c677c6 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Gligar.java @@ -0,0 +1,36 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Confide; +import ru.erius.lab2.move.physical.Facade; +import ru.erius.lab2.move.status.Swagger; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Type; + +import java.util.Arrays; +import java.util.List; + +public class Gligar extends Pokemon { + + protected final static String NAME = "Gligar"; + protected final static List TYPES = Arrays.asList(Type.GROUND, Type.FLYING); + protected final static double + HP = 65.0D, ATTACK = 75.0D, DEFENSE = 105.0D, + SP_ATK = 35.0D, SP_DEF = 65.0D, SPEED = 85.0D; + protected final static List MOVES = Arrays.asList(new Swagger(), new Confide(), new Facade()); + + public Gligar(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Gligar(int lvl) { + this(NAME, lvl); + } + + public Gligar() { + this(NAME, 1); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Gliscor.java b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Gliscor.java new file mode 100644 index 0000000..ea12427 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Gliscor.java @@ -0,0 +1,33 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.Leer; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Type; + +import java.util.Collections; +import java.util.List; + +public class Gliscor extends Gligar { + + protected final static String NAME = "Gliscor"; + protected final static List TYPES = Collections.emptyList(); + protected final static double + HP = 75.0D, ATTACK = 95.0D, DEFENSE = 125.0D, + SP_ATK = 45.0D, SP_DEF = 75.0D, SPEED = 95.0D; + protected final static List MOVES = Collections.singletonList(new Leer()); + + public Gliscor(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Gliscor(int lvl) { + super(lvl); + } + + public Gliscor() { + super(); + } +} diff --git a/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Torchic.java b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Torchic.java new file mode 100644 index 0000000..f914946 --- /dev/null +++ b/sem3/task-custom-make/task/code/ru/erius/lab2/pokemon/Torchic.java @@ -0,0 +1,34 @@ +package ru.erius.lab2.pokemon; + +import ru.erius.lab2.move.status.DoubleTeam; +import ru.erius.lab2.move.status.Rest; +import ru.ifmo.se.pokemon.Move; +import ru.ifmo.se.pokemon.Pokemon; +import ru.ifmo.se.pokemon.Type; + +import java.util.*; + +public class Torchic extends Pokemon { + + protected final static String NAME = "Torchic"; + protected final static List TYPES = Collections.singletonList(Type.FIRE); + protected final static double + HP = 45.0D, ATTACK = 60.0D, DEFENSE = 40.0D, + SP_ATK = 70.0D, SP_DEF = 50.0D, SPEED = 45.0D; + protected final static List MOVES = Arrays.asList(new DoubleTeam(), new Rest()); + + public Torchic(String name, int lvl) { + super(name, lvl); + this.setStats(HP, ATTACK, DEFENSE, SP_ATK, SP_DEF, SPEED); + TYPES.forEach(this::addType); + MOVES.forEach(this::addMove); + } + + public Torchic(int lvl) { + this(NAME, lvl); + } + + public Torchic() { + this(NAME, 1); + } +} diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/Lab2.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/Lab2.class new file mode 100644 index 0000000..46b70f6 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/Lab2.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/physical/Bulldoze.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/physical/Bulldoze.class new file mode 100644 index 0000000..dd9752e Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/physical/Bulldoze.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/physical/Facade.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/physical/Facade.class new file mode 100644 index 0000000..c56fd67 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/physical/Facade.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/special/AirSlash.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/special/AirSlash.class new file mode 100644 index 0000000..3b51a4b Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/special/AirSlash.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/AquaRing.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/AquaRing.class new file mode 100644 index 0000000..156921c Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/AquaRing.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Confide.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Confide.class new file mode 100644 index 0000000..1452e42 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Confide.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/DoubleTeam.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/DoubleTeam.class new file mode 100644 index 0000000..1861402 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/DoubleTeam.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Leer.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Leer.class new file mode 100644 index 0000000..5ef8af7 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Leer.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Rest.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Rest.class new file mode 100644 index 0000000..7381d21 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Rest.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Supersonic.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Supersonic.class new file mode 100644 index 0000000..8225c2c Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Supersonic.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Swagger.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Swagger.class new file mode 100644 index 0000000..1dcbc67 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/move/status/Swagger.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Blaziken.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Blaziken.class new file mode 100644 index 0000000..34e8b8b Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Blaziken.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Combusken.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Combusken.class new file mode 100644 index 0000000..d7d955f Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Combusken.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Comfey.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Comfey.class new file mode 100644 index 0000000..f3ff22e Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Comfey.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Gligar.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Gligar.class new file mode 100644 index 0000000..4959616 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Gligar.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Gliscor.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Gliscor.class new file mode 100644 index 0000000..a41a551 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Gliscor.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Torchic.class b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Torchic.class new file mode 100644 index 0000000..d4de0ea Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/erius/lab2/pokemon/Torchic.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle$1.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle$1.class new file mode 100644 index 0000000..b2e122a Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle$1.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle$2.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle$2.class new file mode 100644 index 0000000..7d0f108 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle$2.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle.class new file mode 100644 index 0000000..82d45ad Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Battle.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/DamageMove.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/DamageMove.class new file mode 100644 index 0000000..bda56cd Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/DamageMove.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Effect.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Effect.class new file mode 100644 index 0000000..c7680ae Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Effect.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/FireMove.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/FireMove.class new file mode 100644 index 0000000..39b7b6e Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/FireMove.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages.class new file mode 100644 index 0000000..9cc93c0 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages_en.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages_en.class new file mode 100644 index 0000000..fc3f678 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages_en.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages_ru_RU.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages_ru_RU.class new file mode 100644 index 0000000..7198ae3 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Messages_ru_RU.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$1.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$1.class new file mode 100644 index 0000000..ca2978b Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$1.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$2.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$2.class new file mode 100644 index 0000000..1a97fa1 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$2.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$3.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$3.class new file mode 100644 index 0000000..1b6c3a4 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move$3.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move.class new file mode 100644 index 0000000..30aa3f3 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Move.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/PhysicalMove.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/PhysicalMove.class new file mode 100644 index 0000000..7a5c6c4 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/PhysicalMove.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Pokemon$1.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Pokemon$1.class new file mode 100644 index 0000000..ae32c18 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Pokemon$1.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Pokemon.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Pokemon.class new file mode 100644 index 0000000..0f9d356 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Pokemon.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/SpecialMove.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/SpecialMove.class new file mode 100644 index 0000000..426b227 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/SpecialMove.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Stat.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Stat.class new file mode 100644 index 0000000..36408e1 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Stat.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Status.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Status.class new file mode 100644 index 0000000..0cdccfe Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Status.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/StatusMove.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/StatusMove.class new file mode 100644 index 0000000..0a92492 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/StatusMove.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Team.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Team.class new file mode 100644 index 0000000..793e117 Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Team.class differ diff --git a/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Type.class b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Type.class new file mode 100644 index 0000000..02db45e Binary files /dev/null and b/sem3/task-custom-make/task/compiled/ru/ifmo/se/pokemon/Type.class differ diff --git a/sem3/task-custom-make/task/doc/allclasses-frame.html b/sem3/task-custom-make/task/doc/allclasses-frame.html new file mode 100644 index 0000000..dea43fa --- /dev/null +++ b/sem3/task-custom-make/task/doc/allclasses-frame.html @@ -0,0 +1,35 @@ + + + + + +All Classes + + + + + +

All Classes

+ + + diff --git a/sem3/task-custom-make/task/doc/allclasses-noframe.html b/sem3/task-custom-make/task/doc/allclasses-noframe.html new file mode 100644 index 0000000..38f65cd --- /dev/null +++ b/sem3/task-custom-make/task/doc/allclasses-noframe.html @@ -0,0 +1,35 @@ + + + + + +All Classes + + + + + +

All Classes

+ + + diff --git a/sem3/task-custom-make/task/doc/constant-values.html b/sem3/task-custom-make/task/doc/constant-values.html new file mode 100644 index 0000000..914a42b --- /dev/null +++ b/sem3/task-custom-make/task/doc/constant-values.html @@ -0,0 +1,498 @@ + + + + + +Constant Field Values + + + + + + + + + + + +
+

Constant Field Values

+

Contents

+ +
+
+ + +

ru.erius.*

+
    +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ru.erius.lab2.pokemon.Blaziken 
    Modifier and TypeConstant FieldValue
    + +protected static final doubleATTACK85.0
    + +protected static final doubleDEFENSE60.0
    + +protected static final doubleHP60.0
    + +protected static final java.lang.StringNAME"Blaziken"
    + +protected static final doubleSP_ATK85.0
    + +protected static final doubleSP_DEF60.0
    + +protected static final doubleSPEED55.0
    +
  • +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ru.erius.lab2.pokemon.Combusken 
    Modifier and TypeConstant FieldValue
    + +protected static final doubleATTACK85.0
    + +protected static final doubleDEFENSE60.0
    + +protected static final doubleHP60.0
    + +protected static final java.lang.StringNAME"Combusken"
    + +protected static final doubleSP_ATK85.0
    + +protected static final doubleSP_DEF60.0
    + +protected static final doubleSPEED55.0
    +
  • +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ru.erius.lab2.pokemon.Comfey 
    Modifier and TypeConstant FieldValue
    + +protected static final doubleATTACK52.0
    + +protected static final doubleDEFENSE90.0
    + +protected static final doubleHP51.0
    + +protected static final java.lang.StringNAME"Comfey"
    + +protected static final doubleSP_ATK82.0
    + +protected static final doubleSP_DEF110.0
    + +protected static final doubleSPEED100.0
    +
  • +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ru.erius.lab2.pokemon.Gligar 
    Modifier and TypeConstant FieldValue
    + +protected static final doubleATTACK75.0
    + +protected static final doubleDEFENSE105.0
    + +protected static final doubleHP65.0
    + +protected static final java.lang.StringNAME"Gligar"
    + +protected static final doubleSP_ATK35.0
    + +protected static final doubleSP_DEF65.0
    + +protected static final doubleSPEED85.0
    +
  • +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ru.erius.lab2.pokemon.Gliscor 
    Modifier and TypeConstant FieldValue
    + +protected static final doubleATTACK95.0
    + +protected static final doubleDEFENSE125.0
    + +protected static final doubleHP75.0
    + +protected static final java.lang.StringNAME"Gliscor"
    + +protected static final doubleSP_ATK45.0
    + +protected static final doubleSP_DEF75.0
    + +protected static final doubleSPEED95.0
    +
  • +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ru.erius.lab2.pokemon.Torchic 
    Modifier and TypeConstant FieldValue
    + +protected static final doubleATTACK60.0
    + +protected static final doubleDEFENSE40.0
    + +protected static final doubleHP45.0
    + +protected static final java.lang.StringNAME"Torchic"
    + +protected static final doubleSP_ATK70.0
    + +protected static final doubleSP_DEF50.0
    + +protected static final doubleSPEED45.0
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/deprecated-list.html b/sem3/task-custom-make/task/doc/deprecated-list.html new file mode 100644 index 0000000..230c4aa --- /dev/null +++ b/sem3/task-custom-make/task/doc/deprecated-list.html @@ -0,0 +1,122 @@ + + + + + +Deprecated List + + + + + + + + +
+ + + + + + + +
+ + +
+

Deprecated API

+

Contents

+
+ +
+ + + + + + + +
+ + + + diff --git a/sem3/task-custom-make/task/doc/help-doc.html b/sem3/task-custom-make/task/doc/help-doc.html new file mode 100644 index 0000000..b1af912 --- /dev/null +++ b/sem3/task-custom-make/task/doc/help-doc.html @@ -0,0 +1,223 @@ + + + + + +API Help + + + + + + + + +
+ + + + + + + +
+ + +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+
    +
  • +

    Overview

    +

    The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

    +
  • +
  • +

    Package

    +

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    +
      +
    • Interfaces (italic)
    • +
    • Classes
    • +
    • Enums
    • +
    • Exceptions
    • +
    • Errors
    • +
    • Annotation Types
    • +
    +
  • +
  • +

    Class/Interface

    +

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    +
      +
    • Class inheritance diagram
    • +
    • Direct Subclasses
    • +
    • All Known Subinterfaces
    • +
    • All Known Implementing Classes
    • +
    • Class/interface declaration
    • +
    • Class/interface description
    • +
    +
      +
    • Nested Class Summary
    • +
    • Field Summary
    • +
    • Constructor Summary
    • +
    • Method Summary
    • +
    +
      +
    • Field Detail
    • +
    • Constructor Detail
    • +
    • Method Detail
    • +
    +

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    +
  • +
  • +

    Annotation Type

    +

    Each annotation type has its own separate page with the following sections:

    +
      +
    • Annotation Type declaration
    • +
    • Annotation Type description
    • +
    • Required Element Summary
    • +
    • Optional Element Summary
    • +
    • Element Detail
    • +
    +
  • +
  • +

    Enum

    +

    Each enum has its own separate page with the following sections:

    +
      +
    • Enum declaration
    • +
    • Enum description
    • +
    • Enum Constant Summary
    • +
    • Enum Constant Detail
    • +
    +
  • +
  • +

    Tree (Class Hierarchy)

    +

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    +
      +
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • +
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • +
    +
  • +
  • +

    Deprecated API

    +

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    +
  • +
  • +

    Index

    +

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    +
  • +
  • +

    Prev/Next

    +

    These links take you to the next or previous class, interface, package, or related page.

    +
  • +
  • +

    Frames/No Frames

    +

    These links show and hide the HTML frames. All pages are available with or without frames.

    +
  • +
  • +

    All Classes

    +

    The All Classes link shows all classes and interfaces except non-static nested types.

    +
  • +
  • +

    Serialized Form

    +

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    +
  • +
  • +

    Constant Field Values

    +

    The Constant Field Values page lists the static final fields and their values.

    +
  • +
+This help file applies to API documentation generated using the standard doclet.
+ +
+ + + + + + + +
+ + + + diff --git a/sem3/task-custom-make/task/doc/index-all.html b/sem3/task-custom-make/task/doc/index-all.html new file mode 100644 index 0000000..7394bcf --- /dev/null +++ b/sem3/task-custom-make/task/doc/index-all.html @@ -0,0 +1,449 @@ + + + + + +Index + + + + + + + + +
+ + + + + + + +
+ + +
A B C D F G H L M N R S T  + + +

A

+
+
AirSlash - Class in ru.erius.lab2.move.special
+
 
+
AirSlash() - Constructor for class ru.erius.lab2.move.special.AirSlash
+
 
+
applyOppEffects(Pokemon) - Method in class ru.erius.lab2.move.physical.Bulldoze
+
 
+
applyOppEffects(Pokemon) - Method in class ru.erius.lab2.move.special.AirSlash
+
 
+
applyOppEffects(Pokemon) - Method in class ru.erius.lab2.move.status.Confide
+
 
+
applyOppEffects(Pokemon) - Method in class ru.erius.lab2.move.status.Leer
+
 
+
applyOppEffects(Pokemon) - Method in class ru.erius.lab2.move.status.Supersonic
+
 
+
applyOppEffects(Pokemon) - Method in class ru.erius.lab2.move.status.Swagger
+
 
+
applySelfEffects(Pokemon) - Method in class ru.erius.lab2.move.status.AquaRing
+
 
+
applySelfEffects(Pokemon) - Method in class ru.erius.lab2.move.status.DoubleTeam
+
 
+
applySelfEffects(Pokemon) - Method in class ru.erius.lab2.move.status.Rest
+
 
+
AquaRing - Class in ru.erius.lab2.move.status
+
 
+
AquaRing() - Constructor for class ru.erius.lab2.move.status.AquaRing
+
 
+
ATTACK - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
ATTACK - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
ATTACK - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
ATTACK - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
ATTACK - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
ATTACK - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
+ + + +

B

+
+
Blaziken - Class in ru.erius.lab2.pokemon
+
 
+
Blaziken(String, int) - Constructor for class ru.erius.lab2.pokemon.Blaziken
+
 
+
Blaziken(int) - Constructor for class ru.erius.lab2.pokemon.Blaziken
+
 
+
Blaziken() - Constructor for class ru.erius.lab2.pokemon.Blaziken
+
 
+
Bulldoze - Class in ru.erius.lab2.move.physical
+
 
+
Bulldoze() - Constructor for class ru.erius.lab2.move.physical.Bulldoze
+
 
+
+ + + +

C

+
+
calcBaseDamage(Pokemon, Pokemon) - Method in class ru.erius.lab2.move.physical.Facade
+
 
+
Combusken - Class in ru.erius.lab2.pokemon
+
 
+
Combusken(String, int) - Constructor for class ru.erius.lab2.pokemon.Combusken
+
 
+
Combusken(int) - Constructor for class ru.erius.lab2.pokemon.Combusken
+
 
+
Combusken() - Constructor for class ru.erius.lab2.pokemon.Combusken
+
 
+
Comfey - Class in ru.erius.lab2.pokemon
+
 
+
Comfey(String, int) - Constructor for class ru.erius.lab2.pokemon.Comfey
+
 
+
Comfey(int) - Constructor for class ru.erius.lab2.pokemon.Comfey
+
 
+
Comfey() - Constructor for class ru.erius.lab2.pokemon.Comfey
+
 
+
Confide - Class in ru.erius.lab2.move.status
+
 
+
Confide() - Constructor for class ru.erius.lab2.move.status.Confide
+
 
+
+ + + +

D

+
+
DEFENSE - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
DEFENSE - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
DEFENSE - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
DEFENSE - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
DEFENSE - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
DEFENSE - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
describe() - Method in class ru.erius.lab2.move.physical.Bulldoze
+
 
+
describe() - Method in class ru.erius.lab2.move.physical.Facade
+
 
+
describe() - Method in class ru.erius.lab2.move.special.AirSlash
+
 
+
describe() - Method in class ru.erius.lab2.move.status.AquaRing
+
 
+
describe() - Method in class ru.erius.lab2.move.status.Confide
+
 
+
describe() - Method in class ru.erius.lab2.move.status.DoubleTeam
+
 
+
describe() - Method in class ru.erius.lab2.move.status.Leer
+
 
+
describe() - Method in class ru.erius.lab2.move.status.Rest
+
 
+
describe() - Method in class ru.erius.lab2.move.status.Supersonic
+
 
+
describe() - Method in class ru.erius.lab2.move.status.Swagger
+
 
+
DoubleTeam - Class in ru.erius.lab2.move.status
+
 
+
DoubleTeam() - Constructor for class ru.erius.lab2.move.status.DoubleTeam
+
 
+
+ + + +

F

+
+
Facade - Class in ru.erius.lab2.move.physical
+
 
+
Facade() - Constructor for class ru.erius.lab2.move.physical.Facade
+
 
+
+ + + +

G

+
+
Gligar - Class in ru.erius.lab2.pokemon
+
 
+
Gligar(String, int) - Constructor for class ru.erius.lab2.pokemon.Gligar
+
 
+
Gligar(int) - Constructor for class ru.erius.lab2.pokemon.Gligar
+
 
+
Gligar() - Constructor for class ru.erius.lab2.pokemon.Gligar
+
 
+
Gliscor - Class in ru.erius.lab2.pokemon
+
 
+
Gliscor(String, int) - Constructor for class ru.erius.lab2.pokemon.Gliscor
+
 
+
Gliscor(int) - Constructor for class ru.erius.lab2.pokemon.Gliscor
+
 
+
Gliscor() - Constructor for class ru.erius.lab2.pokemon.Gliscor
+
 
+
+ + + +

H

+
+
HP - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
HP - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
HP - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
HP - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
HP - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
HP - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
+ + + +

L

+
+
Lab2 - Class in ru.erius.lab2
+
 
+
Lab2() - Constructor for class ru.erius.lab2.Lab2
+
 
+
Leer - Class in ru.erius.lab2.move.status
+
 
+
Leer() - Constructor for class ru.erius.lab2.move.status.Leer
+
 
+
+ + + +

M

+
+
main(String[]) - Static method in class ru.erius.lab2.Lab2
+
 
+
MOVES - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
MOVES - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
MOVES - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
MOVES - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
MOVES - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
MOVES - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
+ + + +

N

+
+
NAME - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
NAME - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
NAME - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
NAME - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
NAME - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
NAME - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
+ + + +

R

+
+
Rest - Class in ru.erius.lab2.move.status
+
 
+
Rest() - Constructor for class ru.erius.lab2.move.status.Rest
+
 
+
ru.erius.lab2 - package ru.erius.lab2
+
 
+
ru.erius.lab2.move.physical - package ru.erius.lab2.move.physical
+
 
+
ru.erius.lab2.move.special - package ru.erius.lab2.move.special
+
 
+
ru.erius.lab2.move.status - package ru.erius.lab2.move.status
+
 
+
ru.erius.lab2.pokemon - package ru.erius.lab2.pokemon
+
 
+
+ + + +

S

+
+
SP_ATK - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
SP_ATK - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
SP_ATK - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
SP_ATK - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
SP_ATK - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
SP_ATK - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
SP_DEF - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
SP_DEF - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
SP_DEF - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
SP_DEF - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
SP_DEF - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
SP_DEF - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
SPEED - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
SPEED - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
SPEED - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
SPEED - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
SPEED - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
SPEED - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
Supersonic - Class in ru.erius.lab2.move.status
+
 
+
Supersonic() - Constructor for class ru.erius.lab2.move.status.Supersonic
+
 
+
Swagger - Class in ru.erius.lab2.move.status
+
 
+
Swagger() - Constructor for class ru.erius.lab2.move.status.Swagger
+
 
+
+ + + +

T

+
+
Torchic - Class in ru.erius.lab2.pokemon
+
 
+
Torchic(String, int) - Constructor for class ru.erius.lab2.pokemon.Torchic
+
 
+
Torchic(int) - Constructor for class ru.erius.lab2.pokemon.Torchic
+
 
+
Torchic() - Constructor for class ru.erius.lab2.pokemon.Torchic
+
 
+
TYPES - Static variable in class ru.erius.lab2.pokemon.Blaziken
+
 
+
TYPES - Static variable in class ru.erius.lab2.pokemon.Combusken
+
 
+
TYPES - Static variable in class ru.erius.lab2.pokemon.Comfey
+
 
+
TYPES - Static variable in class ru.erius.lab2.pokemon.Gligar
+
 
+
TYPES - Static variable in class ru.erius.lab2.pokemon.Gliscor
+
 
+
TYPES - Static variable in class ru.erius.lab2.pokemon.Torchic
+
 
+
+A B C D F G H L M N R S T 
+ +
+ + + + + + + +
+ + + + diff --git a/sem3/task-custom-make/task/doc/index.html b/sem3/task-custom-make/task/doc/index.html new file mode 100644 index 0000000..b38fa86 --- /dev/null +++ b/sem3/task-custom-make/task/doc/index.html @@ -0,0 +1,74 @@ + + + + + +Generated Documentation (Untitled) + + + + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> + + + diff --git a/sem3/task-custom-make/task/doc/overview-frame.html b/sem3/task-custom-make/task/doc/overview-frame.html new file mode 100644 index 0000000..ebe992d --- /dev/null +++ b/sem3/task-custom-make/task/doc/overview-frame.html @@ -0,0 +1,25 @@ + + + + + +Overview List + + + + + + + +

 

+ + diff --git a/sem3/task-custom-make/task/doc/overview-summary.html b/sem3/task-custom-make/task/doc/overview-summary.html new file mode 100644 index 0000000..47dc3ed --- /dev/null +++ b/sem3/task-custom-make/task/doc/overview-summary.html @@ -0,0 +1,149 @@ + + + + + +Overview + + + + + + + + +
+ + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Packages 
PackageDescription
ru.erius.lab2 
ru.erius.lab2.move.physical 
ru.erius.lab2.move.special 
ru.erius.lab2.move.status 
ru.erius.lab2.pokemon 
+
+ +
+ + + + + + + +
+ + + + diff --git a/sem3/task-custom-make/task/doc/overview-tree.html b/sem3/task-custom-make/task/doc/overview-tree.html new file mode 100644 index 0000000..2527ea8 --- /dev/null +++ b/sem3/task-custom-make/task/doc/overview-tree.html @@ -0,0 +1,216 @@ + + + + + +Class Hierarchy + + + + + + + + +
+ + + + + + + +
+ + + +
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • ru.erius.lab2.Lab2
    • +
    • PhysicalMove +
        +
      • ru.erius.lab2.move.physical.Bulldoze
      • +
      +
    • +
    • PhysicalMove +
        +
      • ru.erius.lab2.move.physical.Facade
      • +
      +
    • +
    • Pokemon +
        +
      • ru.erius.lab2.pokemon.Comfey
      • +
      +
    • +
    • Pokemon +
        +
      • ru.erius.lab2.pokemon.Gligar + +
      • +
      +
    • +
    • Pokemon + +
    • +
    • SpecialMove + +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Swagger
      • +
      +
    • +
    • StatusMove + +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Confide
      • +
      +
    • +
    • StatusMove + +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Rest
      • +
      +
    • +
    • StatusMove + +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Leer
      • +
      +
    • +
    +
  • +
+
+ +
+ + + + + + + +
+ + + + diff --git a/sem3/task-custom-make/task/doc/package-list b/sem3/task-custom-make/task/doc/package-list new file mode 100644 index 0000000..1cf5d09 --- /dev/null +++ b/sem3/task-custom-make/task/doc/package-list @@ -0,0 +1,5 @@ +ru.erius.lab2 +ru.erius.lab2.move.physical +ru.erius.lab2.move.special +ru.erius.lab2.move.status +ru.erius.lab2.pokemon diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/Lab2.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/Lab2.html new file mode 100644 index 0000000..a0161be --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/Lab2.html @@ -0,0 +1,269 @@ + + + + + +Lab2 + + + + + + + + + + + + +
+
ru.erius.lab2
+

Class Lab2

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • ru.erius.lab2.Lab2
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Lab2
    +extends java.lang.Object
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Lab2() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + +
      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethod and Description
      static voidmain(java.lang.String[] args) 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Lab2

        +
        public Lab2()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        main

        +
        public static void main(java.lang.String[] args)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/Bulldoze.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/Bulldoze.html new file mode 100644 index 0000000..01ceaf9 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/Bulldoze.html @@ -0,0 +1,287 @@ + + + + + +Bulldoze + + + + + + + + + + + + +
+
ru.erius.lab2.move.physical
+

Class Bulldoze

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • PhysicalMove
    • +
    • +
        +
      • ru.erius.lab2.move.physical.Bulldoze
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Bulldoze
    +extends PhysicalMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Bulldoze() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplyOppEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Bulldoze

        +
        public Bulldoze()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applyOppEffects

        +
        protected void applyOppEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/Facade.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/Facade.html new file mode 100644 index 0000000..39d17f4 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/Facade.html @@ -0,0 +1,289 @@ + + + + + +Facade + + + + + + + + + + + + +
+
ru.erius.lab2.move.physical
+

Class Facade

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • PhysicalMove
    • +
    • +
        +
      • ru.erius.lab2.move.physical.Facade
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Facade
    +extends PhysicalMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Facade() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected doublecalcBaseDamage(Pokemon pokemon, + Pokemon pokemon1) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Facade

        +
        public Facade()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        calcBaseDamage

        +
        protected double calcBaseDamage(Pokemon pokemon,
        +                                Pokemon pokemon1)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-frame.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-frame.html new file mode 100644 index 0000000..378d3d7 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-frame.html @@ -0,0 +1,21 @@ + + + + + +ru.erius.lab2.move.physical + + + + + +

ru.erius.lab2.move.physical

+
+

Classes

+ +
+ + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-summary.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-summary.html new file mode 100644 index 0000000..04960dc --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-summary.html @@ -0,0 +1,144 @@ + + + + + +ru.erius.lab2.move.physical + + + + + + + + + + + +
+

Package ru.erius.lab2.move.physical

+
+
+
    +
  • + + + + + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    Bulldoze 
    Facade 
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-tree.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-tree.html new file mode 100644 index 0000000..5aafe07 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/physical/package-tree.html @@ -0,0 +1,144 @@ + + + + + +ru.erius.lab2.move.physical Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For Package ru.erius.lab2.move.physical

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • PhysicalMove +
        +
      • ru.erius.lab2.move.physical.Facade
      • +
      +
    • +
    • PhysicalMove +
        +
      • ru.erius.lab2.move.physical.Bulldoze
      • +
      +
    • +
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/AirSlash.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/AirSlash.html new file mode 100644 index 0000000..2466798 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/AirSlash.html @@ -0,0 +1,287 @@ + + + + + +AirSlash + + + + + + + + + + + + +
+
ru.erius.lab2.move.special
+

Class AirSlash

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • SpecialMove
    • +
    • +
        +
      • ru.erius.lab2.move.special.AirSlash
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class AirSlash
    +extends SpecialMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      AirSlash() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplyOppEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        AirSlash

        +
        public AirSlash()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applyOppEffects

        +
        protected void applyOppEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-frame.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-frame.html new file mode 100644 index 0000000..6fb1523 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-frame.html @@ -0,0 +1,20 @@ + + + + + +ru.erius.lab2.move.special + + + + + +

ru.erius.lab2.move.special

+
+

Classes

+ +
+ + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-summary.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-summary.html new file mode 100644 index 0000000..9b2af21 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-summary.html @@ -0,0 +1,140 @@ + + + + + +ru.erius.lab2.move.special + + + + + + + + + + + +
+

Package ru.erius.lab2.move.special

+
+
+
    +
  • + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    AirSlash 
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-tree.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-tree.html new file mode 100644 index 0000000..9dff216 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/special/package-tree.html @@ -0,0 +1,139 @@ + + + + + +ru.erius.lab2.move.special Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For Package ru.erius.lab2.move.special

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • SpecialMove + +
    • +
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/AquaRing.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/AquaRing.html new file mode 100644 index 0000000..715c568 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/AquaRing.html @@ -0,0 +1,287 @@ + + + + + +AquaRing + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class AquaRing

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.AquaRing
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class AquaRing
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      AquaRing() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplySelfEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        AquaRing

        +
        public AquaRing()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applySelfEffects

        +
        protected void applySelfEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Confide.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Confide.html new file mode 100644 index 0000000..a11f926 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Confide.html @@ -0,0 +1,287 @@ + + + + + +Confide + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class Confide

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.Confide
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Confide
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Confide() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplyOppEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Confide

        +
        public Confide()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applyOppEffects

        +
        protected void applyOppEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/DoubleTeam.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/DoubleTeam.html new file mode 100644 index 0000000..9c858da --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/DoubleTeam.html @@ -0,0 +1,287 @@ + + + + + +DoubleTeam + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class DoubleTeam

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.DoubleTeam
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class DoubleTeam
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      DoubleTeam() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplySelfEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        DoubleTeam

        +
        public DoubleTeam()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applySelfEffects

        +
        protected void applySelfEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Leer.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Leer.html new file mode 100644 index 0000000..8d38fbc --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Leer.html @@ -0,0 +1,287 @@ + + + + + +Leer + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class Leer

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.Leer
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Leer
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Leer() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplyOppEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Leer

        +
        public Leer()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applyOppEffects

        +
        protected void applyOppEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Rest.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Rest.html new file mode 100644 index 0000000..93dc3da --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Rest.html @@ -0,0 +1,287 @@ + + + + + +Rest + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class Rest

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.Rest
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Rest
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Rest() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplySelfEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Rest

        +
        public Rest()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applySelfEffects

        +
        protected void applySelfEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Supersonic.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Supersonic.html new file mode 100644 index 0000000..8852f4f --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Supersonic.html @@ -0,0 +1,287 @@ + + + + + +Supersonic + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class Supersonic

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.Supersonic
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Supersonic
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Supersonic() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplyOppEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Supersonic

        +
        public Supersonic()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applyOppEffects

        +
        protected void applyOppEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Swagger.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Swagger.html new file mode 100644 index 0000000..bc03bdd --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/Swagger.html @@ -0,0 +1,287 @@ + + + + + +Swagger + + + + + + + + + + + + +
+
ru.erius.lab2.move.status
+

Class Swagger

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • StatusMove
    • +
    • +
        +
      • ru.erius.lab2.move.status.Swagger
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Swagger
    +extends StatusMove
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      Swagger() 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      protected voidapplyOppEffects(Pokemon pokemon) 
      protected java.lang.Stringdescribe() 
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Swagger

        +
        public Swagger()
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        describe

        +
        protected java.lang.String describe()
        +
      • +
      + + + +
        +
      • +

        applyOppEffects

        +
        protected void applyOppEffects(Pokemon pokemon)
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-frame.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-frame.html new file mode 100644 index 0000000..78e77a5 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-frame.html @@ -0,0 +1,26 @@ + + + + + +ru.erius.lab2.move.status + + + + + +

ru.erius.lab2.move.status

+ + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-summary.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-summary.html new file mode 100644 index 0000000..e2acffc --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-summary.html @@ -0,0 +1,164 @@ + + + + + +ru.erius.lab2.move.status + + + + + + + + + + + +
+

Package ru.erius.lab2.move.status

+
+
+ +
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-tree.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-tree.html new file mode 100644 index 0000000..fab8588 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/move/status/package-tree.html @@ -0,0 +1,169 @@ + + + + + +ru.erius.lab2.move.status Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For Package ru.erius.lab2.move.status

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Confide
      • +
      +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Swagger
      • +
      +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Leer
      • +
      +
    • +
    • StatusMove + +
    • +
    • StatusMove + +
    • +
    • StatusMove + +
    • +
    • StatusMove +
        +
      • ru.erius.lab2.move.status.Rest
      • +
      +
    • +
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/package-frame.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/package-frame.html new file mode 100644 index 0000000..92a32e0 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/package-frame.html @@ -0,0 +1,20 @@ + + + + + +ru.erius.lab2 + + + + + +

ru.erius.lab2

+
+

Classes

+ +
+ + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/package-summary.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/package-summary.html new file mode 100644 index 0000000..292b0b2 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/package-summary.html @@ -0,0 +1,140 @@ + + + + + +ru.erius.lab2 + + + + + + + + + + + +
+

Package ru.erius.lab2

+
+
+
    +
  • + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    Lab2 
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/package-tree.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/package-tree.html new file mode 100644 index 0000000..da653bb --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/package-tree.html @@ -0,0 +1,135 @@ + + + + + +ru.erius.lab2 Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For Package ru.erius.lab2

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • ru.erius.lab2.Lab2
    • +
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Blaziken.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Blaziken.html new file mode 100644 index 0000000..7f3c6e8 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Blaziken.html @@ -0,0 +1,444 @@ + + + + + +Blaziken + + + + + + + + + + + + +
+
ru.erius.lab2.pokemon
+

Class Blaziken

+
+
+ +
+
    +
  • +
    +
    +
    public class Blaziken
    +extends Combusken
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected static doubleATTACK 
      protected static doubleDEFENSE 
      protected static doubleHP 
      protected static java.util.List<Move>MOVES 
      protected static java.lang.StringNAME 
      protected static doubleSP_ATK 
      protected static doubleSP_DEF 
      protected static doubleSPEED 
      protected static java.util.List<Type>TYPES 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Blaziken() 
      Blaziken(int lvl) 
      Blaziken(java.lang.String name, + int lvl) 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Blaziken

        +
        public Blaziken(java.lang.String name,
        +                int lvl)
        +
      • +
      + + + +
        +
      • +

        Blaziken

        +
        public Blaziken(int lvl)
        +
      • +
      + + + +
        +
      • +

        Blaziken

        +
        public Blaziken()
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Combusken.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Combusken.html new file mode 100644 index 0000000..770b80f --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Combusken.html @@ -0,0 +1,443 @@ + + + + + +Combusken + + + + + + + + + + + + +
+
ru.erius.lab2.pokemon
+

Class Combusken

+
+
+ +
+
    +
  • +
    +
    Direct Known Subclasses:
    +
    Blaziken
    +
    +
    +
    +
    public class Combusken
    +extends Torchic
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected static doubleATTACK 
      protected static doubleDEFENSE 
      protected static doubleHP 
      protected static java.util.List<Move>MOVES 
      protected static java.lang.StringNAME 
      protected static doubleSP_ATK 
      protected static doubleSP_DEF 
      protected static doubleSPEED 
      protected static java.util.List<Type>TYPES 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Combusken() 
      Combusken(int lvl) 
      Combusken(java.lang.String name, + int lvl) 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Combusken

        +
        public Combusken(java.lang.String name,
        +                 int lvl)
        +
      • +
      + + + +
        +
      • +

        Combusken

        +
        public Combusken(int lvl)
        +
      • +
      + + + +
        +
      • +

        Combusken

        +
        public Combusken()
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Comfey.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Comfey.html new file mode 100644 index 0000000..b40e93a --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Comfey.html @@ -0,0 +1,434 @@ + + + + + +Comfey + + + + + + + + + + + + +
+
ru.erius.lab2.pokemon
+

Class Comfey

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • Pokemon
    • +
    • +
        +
      • ru.erius.lab2.pokemon.Comfey
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class Comfey
    +extends Pokemon
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected static doubleATTACK 
      protected static doubleDEFENSE 
      protected static doubleHP 
      protected static java.util.List<Move>MOVES 
      protected static java.lang.StringNAME 
      protected static doubleSP_ATK 
      protected static doubleSP_DEF 
      protected static doubleSPEED 
      protected static java.util.List<Type>TYPES 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Comfey() 
      Comfey(int lvl) 
      Comfey(java.lang.String name, + int lvl) 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Comfey

        +
        public Comfey(java.lang.String name,
        +              int lvl)
        +
      • +
      + + + +
        +
      • +

        Comfey

        +
        public Comfey(int lvl)
        +
      • +
      + + + +
        +
      • +

        Comfey

        +
        public Comfey()
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Gligar.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Gligar.html new file mode 100644 index 0000000..d11cde6 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Gligar.html @@ -0,0 +1,438 @@ + + + + + +Gligar + + + + + + + + + + + + +
+
ru.erius.lab2.pokemon
+

Class Gligar

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • Pokemon
    • +
    • +
        +
      • ru.erius.lab2.pokemon.Gligar
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    Direct Known Subclasses:
    +
    Gliscor
    +
    +
    +
    +
    public class Gligar
    +extends Pokemon
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected static doubleATTACK 
      protected static doubleDEFENSE 
      protected static doubleHP 
      protected static java.util.List<Move>MOVES 
      protected static java.lang.StringNAME 
      protected static doubleSP_ATK 
      protected static doubleSP_DEF 
      protected static doubleSPEED 
      protected static java.util.List<Type>TYPES 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Gligar() 
      Gligar(int lvl) 
      Gligar(java.lang.String name, + int lvl) 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Gligar

        +
        public Gligar(java.lang.String name,
        +              int lvl)
        +
      • +
      + + + +
        +
      • +

        Gligar

        +
        public Gligar(int lvl)
        +
      • +
      + + + +
        +
      • +

        Gligar

        +
        public Gligar()
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Gliscor.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Gliscor.html new file mode 100644 index 0000000..13f9db3 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Gliscor.html @@ -0,0 +1,439 @@ + + + + + +Gliscor + + + + + + + + + + + + +
+
ru.erius.lab2.pokemon
+

Class Gliscor

+
+
+ +
+
    +
  • +
    +
    +
    public class Gliscor
    +extends Gligar
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected static doubleATTACK 
      protected static doubleDEFENSE 
      protected static doubleHP 
      protected static java.util.List<Move>MOVES 
      protected static java.lang.StringNAME 
      protected static doubleSP_ATK 
      protected static doubleSP_DEF 
      protected static doubleSPEED 
      protected static java.util.List<Type>TYPES 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Gliscor() 
      Gliscor(int lvl) 
      Gliscor(java.lang.String name, + int lvl) 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Gliscor

        +
        public Gliscor(java.lang.String name,
        +               int lvl)
        +
      • +
      + + + +
        +
      • +

        Gliscor

        +
        public Gliscor(int lvl)
        +
      • +
      + + + +
        +
      • +

        Gliscor

        +
        public Gliscor()
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Torchic.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Torchic.html new file mode 100644 index 0000000..5d937a3 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/Torchic.html @@ -0,0 +1,438 @@ + + + + + +Torchic + + + + + + + + + + + + +
+
ru.erius.lab2.pokemon
+

Class Torchic

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • Pokemon
    • +
    • +
        +
      • ru.erius.lab2.pokemon.Torchic
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    Direct Known Subclasses:
    +
    Combusken
    +
    +
    +
    +
    public class Torchic
    +extends Pokemon
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected static doubleATTACK 
      protected static doubleDEFENSE 
      protected static doubleHP 
      protected static java.util.List<Move>MOVES 
      protected static java.lang.StringNAME 
      protected static doubleSP_ATK 
      protected static doubleSP_DEF 
      protected static doubleSPEED 
      protected static java.util.List<Type>TYPES 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Torchic() 
      Torchic(int lvl) 
      Torchic(java.lang.String name, + int lvl) 
      +
    • +
    + +
      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Torchic

        +
        public Torchic(java.lang.String name,
        +               int lvl)
        +
      • +
      + + + +
        +
      • +

        Torchic

        +
        public Torchic(int lvl)
        +
      • +
      + + + +
        +
      • +

        Torchic

        +
        public Torchic()
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-frame.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-frame.html new file mode 100644 index 0000000..3639df1 --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-frame.html @@ -0,0 +1,25 @@ + + + + + +ru.erius.lab2.pokemon + + + + + +

ru.erius.lab2.pokemon

+ + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-summary.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-summary.html new file mode 100644 index 0000000..4c43b1b --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-summary.html @@ -0,0 +1,160 @@ + + + + + +ru.erius.lab2.pokemon + + + + + + + + + + + +
+

Package ru.erius.lab2.pokemon

+
+
+ +
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-tree.html b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-tree.html new file mode 100644 index 0000000..6f0da0b --- /dev/null +++ b/sem3/task-custom-make/task/doc/ru/erius/lab2/pokemon/package-tree.html @@ -0,0 +1,161 @@ + + + + + +ru.erius.lab2.pokemon Class Hierarchy + + + + + + + + + + + +
+

Hierarchy For Package ru.erius.lab2.pokemon

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • Pokemon + +
    • +
    • Pokemon +
        +
      • ru.erius.lab2.pokemon.Gligar + +
      • +
      +
    • +
    • Pokemon +
        +
      • ru.erius.lab2.pokemon.Comfey
      • +
      +
    • +
    +
  • +
+
+ + + + + + diff --git a/sem3/task-custom-make/task/doc/script.js b/sem3/task-custom-make/task/doc/script.js new file mode 100644 index 0000000..b346356 --- /dev/null +++ b/sem3/task-custom-make/task/doc/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/sem3/task-custom-make/task/doc/stylesheet.css b/sem3/task-custom-make/task/doc/stylesheet.css new file mode 100644 index 0000000..98055b2 --- /dev/null +++ b/sem3/task-custom-make/task/doc/stylesheet.css @@ -0,0 +1,574 @@ +/* Javadoc style sheet */ +/* +Overall document style +*/ + +@import url('resources/fonts/dejavu.css'); + +body { + background-color:#ffffff; + color:#353833; + font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; + font-size:14px; + margin:0; +} +a:link, a:visited { + text-decoration:none; + color:#4A6782; +} +a:hover, a:focus { + text-decoration:none; + color:#bb7a2a; +} +a:active { + text-decoration:none; + color:#4A6782; +} +a[name] { + color:#353833; +} +a[name]:hover { + text-decoration:none; + color:#353833; +} +pre { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; +} +h1 { + font-size:20px; +} +h2 { + font-size:18px; +} +h3 { + font-size:16px; + font-style:italic; +} +h4 { + font-size:13px; +} +h5 { + font-size:12px; +} +h6 { + font-size:11px; +} +ul { + list-style-type:disc; +} +code, tt { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; + margin-top:8px; + line-height:1.4em; +} +dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; +} +table tr td dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + vertical-align:top; + padding-top:4px; +} +sup { + font-size:8px; +} +/* +Document title and Copyright styles +*/ +.clear { + clear:both; + height:0px; + overflow:hidden; +} +.aboutLanguage { + float:right; + padding:0px 21px; + font-size:11px; + z-index:200; + margin-top:-9px; +} +.legalCopy { + margin-left:.5em; +} +.bar a, .bar a:link, .bar a:visited, .bar a:active { + color:#FFFFFF; + text-decoration:none; +} +.bar a:hover, .bar a:focus { + color:#bb7a2a; +} +.tab { + background-color:#0066FF; + color:#ffffff; + padding:8px; + width:5em; + font-weight:bold; +} +/* +Navigation bar styles +*/ +.bar { + background-color:#4D7A97; + color:#FFFFFF; + padding:.8em .5em .4em .8em; + height:auto;/*height:1.8em;*/ + font-size:11px; + margin:0; +} +.topNav { + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.bottomNav { + margin-top:10px; + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.subNav { + background-color:#dee3e9; + float:left; + width:100%; + overflow:hidden; + font-size:12px; +} +.subNav div { + clear:left; + float:left; + padding:0 0 5px 6px; + text-transform:uppercase; +} +ul.navList, ul.subNavList { + float:left; + margin:0 25px 0 0; + padding:0; +} +ul.navList li{ + list-style:none; + float:left; + padding: 5px 6px; + text-transform:uppercase; +} +ul.subNavList li{ + list-style:none; + float:left; +} +.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { + color:#FFFFFF; + text-decoration:none; + text-transform:uppercase; +} +.topNav a:hover, .bottomNav a:hover { + text-decoration:none; + color:#bb7a2a; + text-transform:uppercase; +} +.navBarCell1Rev { + background-color:#F8981D; + color:#253441; + margin: auto 5px; +} +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; +} +/* +Page header and footer styles +*/ +.header, .footer { + clear:both; + margin:0 20px; + padding:5px 0 0 0; +} +.indexHeader { + margin:10px; + position:relative; +} +.indexHeader span{ + margin-right:15px; +} +.indexHeader h1 { + font-size:13px; +} +.title { + color:#2c4557; + margin:10px 0; +} +.subTitle { + margin:5px 0 0 0; +} +.header ul { + margin:0 0 15px 0; + padding:0; +} +.footer ul { + margin:20px 0 5px 0; +} +.header ul li, .footer ul li { + list-style:none; + font-size:13px; +} +/* +Heading styles +*/ +div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList ul.blockList li.blockList h3 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList li.blockList h3 { + padding:0; + margin:15px 0; +} +ul.blockList li.blockList h2 { + padding:0px 0 20px 0; +} +/* +Page layout container styles +*/ +.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { + clear:both; + padding:10px 20px; + position:relative; +} +.indexContainer { + margin:10px; + position:relative; + font-size:12px; +} +.indexContainer h2 { + font-size:13px; + padding:0 0 3px 0; +} +.indexContainer ul { + margin:0; + padding:0; +} +.indexContainer ul li { + list-style:none; + padding-top:2px; +} +.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { + font-size:12px; + font-weight:bold; + margin:10px 0 0 0; + color:#4E4E4E; +} +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:5px 0 10px 0px; + font-size:14px; + font-family:'DejaVu Sans Mono',monospace; +} +.serializedFormContainer dl.nameValue dt { + margin-left:1px; + font-size:1.1em; + display:inline; + font-weight:bold; +} +.serializedFormContainer dl.nameValue dd { + margin:0 0 0 1px; + font-size:1.1em; + display:inline; +} +/* +List styles +*/ +ul.horizontal li { + display:inline; + font-size:0.9em; +} +ul.inheritance { + margin:0; + padding:0; +} +ul.inheritance li { + display:inline; + list-style:none; +} +ul.inheritance li ul.inheritance { + margin-left:15px; + padding-left:15px; + padding-top:1px; +} +ul.blockList, ul.blockListLast { + margin:10px 0 10px 0; + padding:0; +} +ul.blockList li.blockList, ul.blockListLast li.blockList { + list-style:none; + margin-bottom:15px; + line-height:1.4; +} +ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { + padding:0px 20px 5px 10px; + border:1px solid #ededed; + background-color:#f8f8f8; +} +ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { + padding:0 0 5px 8px; + background-color:#ffffff; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { + margin-left:0; + padding-left:0; + padding-bottom:15px; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { + list-style:none; + border-bottom:none; + padding-bottom:0; +} +table tr td dl, table tr td dl dt, table tr td dl dd { + margin-top:0; + margin-bottom:1px; +} +/* +Table styles +*/ +.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { + width:100%; + border-left:1px solid #EEE; + border-right:1px solid #EEE; + border-bottom:1px solid #EEE; +} +.overviewSummary, .memberSummary { + padding:0px; +} +.overviewSummary caption, .memberSummary caption, .typeSummary caption, +.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { + position:relative; + text-align:left; + background-repeat:no-repeat; + color:#253441; + font-weight:bold; + clear:none; + overflow:hidden; + padding:0px; + padding-top:10px; + padding-left:1px; + margin:0px; + white-space:pre; +} +.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, +.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, +.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, +.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, +.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, +.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, +.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, +.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { + color:#FFFFFF; +} +.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, +.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + padding-bottom:7px; + display:inline-block; + float:left; + background-color:#F8981D; + border: none; + height:16px; +} +.memberSummary caption span.activeTableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#F8981D; + height:16px; +} +.memberSummary caption span.tableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#4D7A97; + height:16px; +} +.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { + padding-top:0px; + padding-left:0px; + padding-right:0px; + background-image:none; + float:none; + display:inline; +} +.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, +.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { + display:none; + width:5px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .activeTableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .tableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + background-color:#4D7A97; + float:left; + +} +.overviewSummary td, .memberSummary td, .typeSummary td, +.useSummary td, .constantsSummary td, .deprecatedSummary td { + text-align:left; + padding:0px 0px 12px 10px; +} +th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, +td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ + vertical-align:top; + padding-right:0px; + padding-top:8px; + padding-bottom:3px; +} +th.colFirst, th.colLast, th.colOne, .constantsSummary th { + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} +td.colFirst, th.colFirst { + white-space:nowrap; + font-size:13px; +} +td.colLast, th.colLast { + font-size:13px; +} +td.colOne, th.colOne { + font-size:13px; +} +.overviewSummary td.colFirst, .overviewSummary th.colFirst, +.useSummary td.colFirst, .useSummary th.colFirst, +.overviewSummary td.colOne, .overviewSummary th.colOne, +.memberSummary td.colFirst, .memberSummary th.colFirst, +.memberSummary td.colOne, .memberSummary th.colOne, +.typeSummary td.colFirst{ + width:25%; + vertical-align:top; +} +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; +} +.tableSubHeadingColor { + background-color:#EEEEFF; +} +.altColor { + background-color:#FFFFFF; +} +.rowColor { + background-color:#EEEEEF; +} +/* +Content styles +*/ +.description pre { + margin-top:0; +} +.deprecatedContent { + margin:0; + padding:10px 0; +} +.docSummary { + padding:0; +} + +ul.blockList ul.blockList ul.blockList li.blockList h3 { + font-style:normal; +} + +div.block { + font-size:14px; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; +} + +td.colLast div { + padding-top:0px; +} + + +td.colLast a { + padding-bottom:3px; +} +/* +Formatting effect styles +*/ +.sourceLineNo { + color:green; + padding:0 30px 0 0; +} +h1.hidden { + visibility:hidden; + overflow:hidden; + font-size:10px; +} +.block { + display:block; + margin:3px 10px 2px 0px; + color:#474747; +} +.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, +.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, +.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { + font-weight:bold; +} +.deprecationComment, .emphasizedPhrase, .interfaceName { + font-style:italic; +} + +div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, +div.block div.block span.interfaceName { + font-style:normal; +} + +div.contentContainer ul.blockList li.blockList h2{ + padding-bottom:0px; +} diff --git a/sem3/task-custom-make/task/fatJar/.makefile.swp b/sem3/task-custom-make/task/fatJar/.makefile.swp new file mode 100644 index 0000000..a4f0ee5 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/.makefile.swp differ diff --git a/sem3/task-custom-make/task/fatJar/Lab2.jar b/sem3/task-custom-make/task/fatJar/Lab2.jar new file mode 100644 index 0000000..319592a Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/Lab2.jar differ diff --git a/sem3/task-custom-make/task/fatJar/MANIFEST.MF b/sem3/task-custom-make/task/fatJar/MANIFEST.MF new file mode 100644 index 0000000..4c3a9ea --- /dev/null +++ b/sem3/task-custom-make/task/fatJar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Verison: 1.0 +Main-Class: ru.erius.lab2.Lab2 diff --git a/sem3/task-custom-make/task/fatJar/bild.sh b/sem3/task-custom-make/task/fatJar/bild.sh new file mode 100644 index 0000000..e69de29 diff --git a/sem3/task-custom-make/task/fatJar/build.sh b/sem3/task-custom-make/task/fatJar/build.sh new file mode 100644 index 0000000..890f55a --- /dev/null +++ b/sem3/task-custom-make/task/fatJar/build.sh @@ -0,0 +1,7 @@ +cd ~/prog/lab2/task/fatJar +mkdir -p ../compiled +javac -d ../compiled -g $(find ../code -name *.java) -cp ../Pokemon.jar +cd ../compiled +jar -xf ../Pokemon.jar ru +cd ../fatJar +jar -cfm Lab2.jar MANIFEST.MF -C ../compiled/ ru diff --git a/sem3/task-custom-make/task/fatJar/jar b/sem3/task-custom-make/task/fatJar/jar new file mode 100644 index 0000000..739323b Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/jar differ diff --git a/sem3/task-custom-make/task/fatJar/makefile b/sem3/task-custom-make/task/fatJar/makefile new file mode 100644 index 0000000..209158c --- /dev/null +++ b/sem3/task-custom-make/task/fatJar/makefile @@ -0,0 +1,15 @@ +COMPILED=../compiled +DEPS=../Pokemon.jar +GROUP=ru + +%.javac: %.java + javac -d $(COMPILED) -g $< -cp $(DEPS) + +jar: MANIFEST.MF + cd $(COMPILED) + jar -xf $(DEPS) $(GROUP) + cd - + jar -cfm $@ $< -C $(COMPILED) $(GROUP) + +.PHONY: all + diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle$1.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle$1.class new file mode 100644 index 0000000..b2e122a Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle$1.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle$2.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle$2.class new file mode 100644 index 0000000..7d0f108 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle$2.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle.class new file mode 100644 index 0000000..82d45ad Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Battle.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/DamageMove.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/DamageMove.class new file mode 100644 index 0000000..bda56cd Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/DamageMove.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Effect.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Effect.class new file mode 100644 index 0000000..c7680ae Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Effect.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/FireMove.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/FireMove.class new file mode 100644 index 0000000..39b7b6e Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/FireMove.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages.class new file mode 100644 index 0000000..9cc93c0 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages_en.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages_en.class new file mode 100644 index 0000000..fc3f678 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages_en.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages_ru_RU.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages_ru_RU.class new file mode 100644 index 0000000..7198ae3 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Messages_ru_RU.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$1.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$1.class new file mode 100644 index 0000000..ca2978b Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$1.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$2.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$2.class new file mode 100644 index 0000000..1a97fa1 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$2.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$3.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$3.class new file mode 100644 index 0000000..1b6c3a4 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move$3.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move.class new file mode 100644 index 0000000..30aa3f3 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Move.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/PhysicalMove.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/PhysicalMove.class new file mode 100644 index 0000000..7a5c6c4 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/PhysicalMove.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Pokemon$1.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Pokemon$1.class new file mode 100644 index 0000000..ae32c18 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Pokemon$1.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Pokemon.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Pokemon.class new file mode 100644 index 0000000..0f9d356 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Pokemon.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/SpecialMove.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/SpecialMove.class new file mode 100644 index 0000000..426b227 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/SpecialMove.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Stat.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Stat.class new file mode 100644 index 0000000..36408e1 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Stat.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Status.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Status.class new file mode 100644 index 0000000..0cdccfe Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Status.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/StatusMove.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/StatusMove.class new file mode 100644 index 0000000..0a92492 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/StatusMove.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Team.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Team.class new file mode 100644 index 0000000..793e117 Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Team.class differ diff --git a/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Type.class b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Type.class new file mode 100644 index 0000000..02db45e Binary files /dev/null and b/sem3/task-custom-make/task/fatJar/ru/ifmo/se/pokemon/Type.class differ diff --git a/sem3/task-custom-make/task/modular/Lab2.jar b/sem3/task-custom-make/task/modular/Lab2.jar new file mode 100644 index 0000000..753575f Binary files /dev/null and b/sem3/task-custom-make/task/modular/Lab2.jar differ diff --git a/sem3/task-custom-make/task/modular/MANIFEST.MF b/sem3/task-custom-make/task/modular/MANIFEST.MF new file mode 100644 index 0000000..5d87186 --- /dev/null +++ b/sem3/task-custom-make/task/modular/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Verison: 1.0 +Main-Class: ru.erius.lab2.Lab2 +Class-Path: ../Pokemon.jar diff --git a/sem3/task-custom-make/task/modular/build.sh b/sem3/task-custom-make/task/modular/build.sh new file mode 100644 index 0000000..bc7fefd --- /dev/null +++ b/sem3/task-custom-make/task/modular/build.sh @@ -0,0 +1,4 @@ +cd ~/prog/lab2/task/modular +mkdir -p ../compiled +javac -d ../compiled -g $(find ../code -name *.java) -cp ../Pokemon.jar +jar -cfm Lab2.jar MANIFEST.MF -C ../compiled ru/erius diff --git a/sem3/task-hex-make/lib.asm b/sem3/task-hex-make/lib.asm new file mode 100644 index 0000000..1464127 --- /dev/null +++ b/sem3/task-hex-make/lib.asm @@ -0,0 +1,32 @@ +section .data + +codes: db '0123456789ABCDEF' + +section .text + +global print_hex +global exit +print_hex: + mov rdi, 1 + mov rdx, 1 + mov rcx, 64 + .loop: + push rax + sub rcx, 4 + sar rax, cl + and rax, 0xf + lea rsi, [codes + rax] + mov rax, 1 + push rcx + syscall + pop rcx + pop rax + test rcx, rcx + jnz .loop + ret + +exit: + mov rax, 60 + xor rdi, rdi + syscall + diff --git a/sem3/task-hex-make/lib.inc b/sem3/task-hex-make/lib.inc new file mode 100644 index 0000000..c70c4e0 --- /dev/null +++ b/sem3/task-hex-make/lib.inc @@ -0,0 +1,3 @@ +extern print_hex +extern exit + diff --git a/sem3/task-hex-make/lib.o b/sem3/task-hex-make/lib.o new file mode 100644 index 0000000..a398cec Binary files /dev/null and b/sem3/task-hex-make/lib.o differ diff --git a/sem3/task-hex-make/main b/sem3/task-hex-make/main new file mode 100644 index 0000000..c8034ed Binary files /dev/null and b/sem3/task-hex-make/main differ diff --git a/sem3/task-hex-make/main.asm b/sem3/task-hex-make/main.asm new file mode 100644 index 0000000..8edd24d --- /dev/null +++ b/sem3/task-hex-make/main.asm @@ -0,0 +1,10 @@ +%include "lib.inc" + +section .text + +global _start +_start: + mov rax, 0x7632FEED + call print_hex + call exit + diff --git a/sem3/task-hex-make/main.o b/sem3/task-hex-make/main.o new file mode 100644 index 0000000..6ef76f3 Binary files /dev/null and b/sem3/task-hex-make/main.o differ diff --git a/sem3/task-hex-make/makefile b/sem3/task-hex-make/makefile new file mode 100644 index 0000000..ce4a7c6 --- /dev/null +++ b/sem3/task-hex-make/makefile @@ -0,0 +1,14 @@ +ASM=nasm -f elf64 +LD=ld + +main: main.o lib.o + $(LD) -o $@ $^ + +main.o: main.asm lib.inc + $(ASM) -o $@ $< + +%.o: %.asm + $(ASM) -o $@ $< + +.PHONY: all + diff --git a/sem3/task-macro/macro.asm b/sem3/task-macro/macro.asm new file mode 100644 index 0000000..e823962 --- /dev/null +++ b/sem3/task-macro/macro.asm @@ -0,0 +1,6 @@ +%macro test 3 +db %1, ",", %2, ",", %3 +%endmacro + +test "hello", ",", " world" + diff --git a/sem3/task-macro/macro.o b/sem3/task-macro/macro.o new file mode 100644 index 0000000..1674b18 --- /dev/null +++ b/sem3/task-macro/macro.o @@ -0,0 +1,4 @@ +%line 4+1 macro.asm + +db "hello", ",", ",", ",", " world" + diff --git a/sem4/hello b/sem4/hello new file mode 100644 index 0000000..aefe90e Binary files /dev/null and b/sem4/hello differ diff --git a/sem4/hello.c b/sem4/hello.c new file mode 100644 index 0000000..0fa5266 --- /dev/null +++ b/sem4/hello.c @@ -0,0 +1,12 @@ +#include + +extern void print_string(char* str); +extern void print_file(char* fileName); + +/* hello.c */ +int main() { + print_string("Enter the file name: "); + char input[255]; + scanf("%s", input); + print_file(input); +} diff --git a/sem4/hello.o b/sem4/hello.o new file mode 100644 index 0000000..e45472b Binary files /dev/null and b/sem4/hello.o differ diff --git a/sem4/hello.txt b/sem4/hello.txt new file mode 100644 index 0000000..1392d23 --- /dev/null +++ b/sem4/hello.txt @@ -0,0 +1 @@ +Hello, mmap! diff --git a/sem4/hello_mmap b/sem4/hello_mmap new file mode 100644 index 0000000..20d7462 Binary files /dev/null and b/sem4/hello_mmap differ diff --git a/sem4/hello_mmap.asm b/sem4/hello_mmap.asm new file mode 100644 index 0000000..e4a63da --- /dev/null +++ b/sem4/hello_mmap.asm @@ -0,0 +1,122 @@ +; hello_mmap.asm +%define O_RDONLY 0 +%define PROT_READ 0x1 +%define MAP_PRIVATE 0x2 +%define SYS_WRITE 1 +%define SYS_OPEN 2 +%define SYS_CLOSE 3 +%define SYS_FSTAT 5 +%define SYS_MMAP 9 +%define SYS_MUNMAP 11 +%define SYS_EXIT 60 +%define FD_STDOUT 1 +%define FSTAT_SIZE 144 +%define FSTAT_FSIZE_OFFSET 48 + +global print_file +global print_string + +section .data + fstat_buff: db "hello", 0 + +section .text + +; use exit system call to shut down correctly +exit: + mov rax, SYS_EXIT + xor rdi, rdi + syscall + +; These functions are used to print a null terminated string +; rdi holds a string pointer +print_string: + push rdi + call string_length + pop rsi + mov rdx, rax + mov rax, SYS_WRITE + mov rdi, FD_STDOUT + syscall + ret + +string_length: + xor rax, rax +.loop: + cmp byte [rdi+rax], 0 + je .end + inc rax + jmp .loop +.end: + ret + +; This function is used to print a substring with given length +; rdi holds a string pointer +; rsi holds a substring length +print_substring: + mov rdx, rsi + mov rsi, rdi + mov rax, SYS_WRITE + mov rdi, FD_STDOUT + syscall + ret + +; rdi - file name +print_file: + push r12 + push r13 + ; Вызовите open и откройте fname в режиме read only. + mov rax, SYS_OPEN + mov rsi, O_RDONLY ; Open file read only + xor rdx, rdx ; We are not creating a file + ; so this argument has no meaning + syscall + ; rax holds the opened file descriptor now + mov r12, rax ; save fd to r12 + + ; get stat of file + mov rdi, r12 + mov rsi, fstat_buff + mov rax, SYS_FSTAT + syscall + + ; get size of file in from its stats + mov r13, fstat_buff + add r13, FSTAT_FSIZE_OFFSET + mov r13, [r13] + ; now rsi stores the files size + + ; Вызовите mmap c правильными аргументами + ; Дайте операционной системе самой выбрать, куда отобразить файл + ; Размер области возьмите в размер страницы + ; Область не должна быть общей для нескольких процессов + ; и должна выделяться только для чтения. + xor rdi, rdi + mov r8, r12 + xor r9, r9 + mov rsi, r13 + mov rdx, PROT_READ + mov r10, MAP_PRIVATE + mov rax, SYS_MMAP + syscall + ; now rax stores the mapped file address + + ; с помощью print_substring теперь можно вывести его содержимое + push rax ; save mapped file address + mov rdi, rax + mov rsi, r13 + call print_substring + + ; unmap mapped file + pop rdi ; retrieve mapped file address from stack + mov rsi, r13 + mov rax, SYS_MUNMAP + syscall + + ; close file + mov rdi, r12 + mov rax, SYS_CLOSE + syscall + + pop r13 + pop r12 + ret diff --git a/sem4/hello_mmap.o b/sem4/hello_mmap.o new file mode 100644 index 0000000..776e560 Binary files /dev/null and b/sem4/hello_mmap.o differ diff --git a/sem4/makefile b/sem4/makefile new file mode 100644 index 0000000..b7d48a0 --- /dev/null +++ b/sem4/makefile @@ -0,0 +1,25 @@ +GCC = gcc +ASM = nasm +ASMFLAGS = -felf64 -g + +# Если есть код на C, то компоновку тоже нужно производить +# с помощью gcc, а не ld +hello: hello.o hello_mmap.o + $(GCC) $^ -o $@ + +# target : dependencies +# do this +hello.o: hello.c + $(GCC) -c $^ -o $@ + +%.o: %.asm + $(ASM) $(ASMFLAGS) $^ -o $@ + +clean: + $(RM) hello + $(RM) hello.o + $(RM) hello_mmap.o + +all: hello + +.PHONY: clean all diff --git a/sem4/string.asm b/sem4/string.asm new file mode 100644 index 0000000..8587d36 --- /dev/null +++ b/sem4/string.asm @@ -0,0 +1,39 @@ +; string.asm +global world +global print_string + +section .rodata +message: db ", world!", 10, 0 + +section .text + +string_length: + mov rax, 0 + .loop: + xor rax, rax + .count: + cmp byte [rdi+rax], 0 + je .end + inc rax + jmp .count + .end: + ret + +world: + mov rdi, message + +print_string: + push rax + push rdi + call string_length + mov rsi, [rsp] + mov rdx, rax + mov rax, 1 + mov rdi, 1 + push rcx + syscall + pop rcx + pop rdi + pop rax + ret + diff --git a/sem5/ast.png b/sem5/ast.png new file mode 100644 index 0000000..c8caa84 Binary files /dev/null and b/sem5/ast.png differ diff --git a/sem5/generic_list b/sem5/generic_list new file mode 100644 index 0000000..1a07c8f Binary files /dev/null and b/sem5/generic_list differ diff --git a/sem5/generic_list.c b/sem5/generic_list.c new file mode 100644 index 0000000..a306987 --- /dev/null +++ b/sem5/generic_list.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +#define DEFINE_LIST(type) \ + struct list_##type { \ + type value; \ + struct list_##type *next; \ + }; \ + struct list_##type *list_##type##_create(type value) { \ + struct list_##type *list = (void *) malloc(sizeof(struct list_##type)); \ + if (list == NULL) \ + return NULL; \ + list->value = value; \ + list->next = NULL; \ + return list; \ + } \ + void list_##type##_free(struct list_##type *list) { \ + struct list_##type *temp; \ + while (list != NULL) { \ + temp = list; \ + list = list->next; \ + free(temp); \ + } \ + } \ + void list_##type##_push(struct list_##type *list, type value) { \ + if (list == NULL) return; + while (list->next != NULL) list = list->next; \ + struct list_##type *item = list_##type##_create(value); \ + list->next = item; \ + } \ + void list_##type##_print(struct list_##type *list, char* format) { \ + while (list != NULL) { \ + printf(format, list->value); \ + list = list->next; \ + } \ + printf("\n"); \ + } + +#define list_create(value) \ + _Generic((value), \ + int64_t : list_int64_t_create(value), \ + double : list_double_create(value), \ + default : printf("This type is not supported\n")) + +#define list_free(list) \ + _Generic((list), \ + struct list_int64_t : list_int64_t_free(list), \ + struct list_double : list_double_free(list), \ + default : printf("This type is not supported\n")) + +#define list_push(list, value) \ + _Generic((value), \ + int64_t : list_int64_t_push(list, value), \ + double : list_double_push(list, value), \ + default : printf("This type is not supported\n")) + +#define list_print(list) \ + _Generic((*list), \ + struct list_int64_t : list_int64_t_print(list, "%d "), \ + struct list_double : list_double_print(list, "%lf "), \ + default : printf("This type is not supported\n")) + +DEFINE_LIST(int64_t); +DEFINE_LIST(double); + +int main() { + struct list_int64_t *list = list_create((int64_t) 5); + list_push(list, (int64_t) 2); + list_push(list, (int64_t) 1); + list_print(list); + + struct list_double *list2 = list_create((double) 2.2); + list_push(list2, (double) 0.1); + list_push(list2, (double) 5.7); + list_print(list2); + + return 0; +} diff --git a/sem5/print_var b/sem5/print_var new file mode 100644 index 0000000..d15ca45 Binary files /dev/null and b/sem5/print_var differ diff --git a/sem5/print_var.c b/sem5/print_var.c new file mode 100644 index 0000000..ccd7752 --- /dev/null +++ b/sem5/print_var.c @@ -0,0 +1,11 @@ +#include +#define print_var(x) printf(#x " is %d\n", x) +#define var 22 + +int main() { + int x = 6; + print_var(x); + print_var(42); + print_var(var); + return 0; +} diff --git a/sem5/printer b/sem5/printer new file mode 100644 index 0000000..1813e59 Binary files /dev/null and b/sem5/printer differ diff --git a/sem5/printer.c b/sem5/printer.c new file mode 100644 index 0000000..452c706 --- /dev/null +++ b/sem5/printer.c @@ -0,0 +1,119 @@ +#include +#include +#include +#include + +struct AST { + enum AST_type { AST_BINOP, AST_UNOP, AST_LIT } type; + union { + struct binop { + enum binop_type { BIN_PLUS, BIN_MINUS, BIN_MUL, BIN_DIV } type; + struct AST *left, *right; + } as_binop; + struct unop { + enum unop_type { UN_NEG } type; + struct AST *operand; + } as_unop; + struct literal { + int64_t value; + } as_literal; + }; +}; + +/* DSL */ +static struct AST *newnode(struct AST ast) { + struct AST *const node = malloc(sizeof(struct AST)); + *node = ast; + return node; +} + +struct AST _lit(int64_t value) { + return (struct AST){AST_LIT, .as_literal = {value}}; +} + +struct AST *lit(int64_t value) { + return newnode(_lit(value)); +} +struct AST _unop(enum unop_type type, struct AST *operand) { + return (struct AST){AST_UNOP, .as_unop = {type, operand}}; +} + +struct AST *unop(enum unop_type type, struct AST *operand) { + return newnode(_unop(type, operand)); +} + +struct AST _binop(enum binop_type type, struct AST *left, struct AST *right) { + return (struct AST){AST_BINOP, .as_binop = {type, left, right}}; +} +struct AST *binop(enum binop_type type, struct AST *left, struct AST *right) { + return newnode(_binop(type, left, right)); +} +#define DECLARE_BINOP(fun, code) \ + struct AST *fun(struct AST *left, struct AST *right) { \ + return binop(BIN_##code, left, right); \ + } +DECLARE_BINOP(add, PLUS) +DECLARE_BINOP(mul, MUL) +DECLARE_BINOP(sub, MINUS) +DECLARE_BINOP(div, DIV) + +#undef DECLARE_BINOP +#define DECLARE_UNOP(fun, code) \ + struct AST *fun(struct AST *operand) { \ + return unop(UN_##code, operand); \ + } +DECLARE_UNOP(neg, NEG) +#undef DECLARE_UNOP +/* printer */ + +static const char *BINOPS[] = { + [BIN_PLUS] = "+", [BIN_MINUS] = "-", [BIN_MUL] = "*", [BIN_DIV] = "/"}; +static const char *UNOPS[] = {[UN_NEG] = "-"}; + +typedef void(printer)(FILE *, struct AST *); + +void print(FILE *f, struct AST *ast); + +void print_binop(FILE *f, struct AST *ast) { + fprintf(f, "("); + print(f, ast->as_binop.left); + fprintf(f, ")"); + fprintf(f, "%s", BINOPS[ast->as_binop.type]); + fprintf(f, "("); + print(f, ast->as_binop.right); + fprintf(f, ")"); +} +void print_unop(FILE *f, struct AST *ast) { + fprintf(f, "(%s", UNOPS[ast->as_unop.type]); + print(f, ast->as_unop.operand); + fprintf(f, ")"); +} +void print_lit(FILE *f, struct AST *ast) { + fprintf(f, "%" PRId64, ast->as_literal.value); +} + +static printer *ast_printers[] = { + [AST_BINOP] = print_binop, [AST_UNOP] = print_unop, [AST_LIT] = print_lit}; + +void print(FILE *f, struct AST *ast) { + if (ast) + ast_printers[ast->type](f, ast); + else + fprintf(f, ""); +} + +int main() { + struct AST *ast = binop(BIN_PLUS, lit(999), lit(728));; + print(stdout, ast); + printf("\n"); + + ast = binop(BIN_PLUS, lit(4), binop(BIN_MUL, lit(2), lit(9))); + print(stdout, ast); + printf("\n"); + + ast = binop(BIN_MUL, binop(BIN_PLUS, lit(3), lit(5)), binop(BIN_DIV, lit(9), lit(7))); + print(stdout, ast); + printf("\n"); + + return 0; +} diff --git a/sem6/README.org b/sem6/README.org new file mode 100644 index 0000000..84cf710 --- /dev/null +++ b/sem6/README.org @@ -0,0 +1,201 @@ +#+LANG: ru +#+TITLE: Семинар 6: Аллокация памяти, арихитектура + + +* Что такое куча + +В рамках этого семинара мы познакомимся с тем, как может быть устроена куча. + +С данными связана такая характеристика как /время жизни/. +Это тот промежуток выполнения программы, когда обращаться к этим данным корректно и не ведёт к неопределённому поведению. + +Данные в C могут быть выделены следующими способами: + +- Автоматически: локальные переменные функций создаются в момент их запуска и живут до их завершения. + Правильно сказать: гарантированное время жизни переменных от запуска функции до её завершения. + + Зная, что компиляторы оптимизируют локальные переменные, мы больше не будем говорить, что они выделяются в стеке. + +- Глобальные переменные и локальные переменные функций, если локальные переменные помечены =static=. + + И те, и другие создаются в глобальной области данных. + +Других гарантированно возможных способов выделить память в "голом" C нет. + + +Чтобы выделить память в стеке или в глобальной области данных необходимо знать, сколько именно памяти понадобится, уже в момент компиляции. +Однако иногда мы не знаем этого заранее; например, когда принимаем по сети размер строки и саму строку; её нужно где-то выделить, а сколько под это выделять байт --- неясно. + +В таком случае приходится использовать =аллокаторы= --- специальные программы, которые умеют резервировать области памяти и управляют тем, где будут находиться блоки памяти, которые программист запрашивает. + +Функции =malloc=, =calloc=, =realloc=, =free= --- это интерфейс к аллокатору из стандартной библиотеки C. +С помощью вызова =malloc= можно выделить память, время жизни которой будет неопределённо долгим. Она может существовать до завершения работы программы, как глобальные переменные, или быть возвращена для переиспользования с помощью функции =free=. + + +Некоторые советы по работе с памятью: + +- Если вам нужно выделить память, подумайте, нельзя ли её выделить в стеке. Это всегда проще, чем в куче. +- Не стесняйтесь передавать не очень большие структуры по значению. + + +* Аллокатор блоков + +Самый простой аллокатор возвращает блоки фиксированного размера. +Их можно заполнять не полностью, остаток будет теряться. +Помимо блоков нужно хранить карту их занятости; здесь она хранится в виде массива =bool='ов, но для компактности можно было бы упаковывать булевы значения по восемь в каждый байт. + +#+begin_src c + +#define HEAP_BLOCKS 80 +#define BLOCK_CAPACITY 1024 + +struct heap { + struct block { + char contents[BLOCK_CAPACITY]; + } blocks[HEAP_BLOCKS]; + bool is_occupied[HEAP_BLOCKS]; +} global_heap = {0}; +#+end_src + + +*Задание 1* Изучите файл [[./heap-0.c][heap-0.c]] и реализуйте в нём недостающие функции для резервирования блока и для возвращения блока в пул доступных. Почему =block_id= содержит ссылку на =struct heap=? + +** Аллокатор множества блоков + + +В предыдущем аллокаторе есть несколько существенных недостатков: + +- блоки и заголовки перемежаются, и размер блоков фиксирован, поэтому нельзя занять несколько блоков подряд. +- размер блока фиксирован, и потому мы можем нести накланые расходы по памяти. + + +*Задание 2* Модифицируйте аллокатор так, чтобы он умел выделять несколько блоков подряд. +См. файл [[./heap-1.c][heap-1.c]]. У блоков теперь будет статус с большей гранулярностью, нежели "занят --- не занят". +Придумайте тесты для вашего кода для проверки всех особых случаев. + +#+begin_src c +enum block_status { BLK_FREE = 0, BLK_ONE, BLK_FIRST, BLK_CONT, BLK_LAST }; +#+end_src + +Блоки будут связываться в одну из следующих конфигураций: + +#+begin_src c +BLK_FREE // свободный блок +BLK_ONE // единичный занятый блок. +// после него или свободный или занятый другими данными. + +BLK_FIRST, BLK_CONT, BLK_CONT, BLK_LAST +// последовательность блоков с началом, серединкой и концом. + +BLK_FIRST, BLK_LAST // то же, но без серединки. + +#+end_src + +Выделение памяти должно привести к выделению адекватного количества блоков; освобождение памяти должно привести к освобождению блоков начиная с указанного, если этот блок -- начало. + + +** Чего не хватает для эффективности? + +Чтобы аллокатор стал более эффективным, можно отказаться от фиксированного размера блока, снабдив каждый из них заголовком и организовав в связный список. +Затем из единой непрерывной кучи можно сделать несколько фрагментов и добавить довыделение памяти (а именно страниц от операционной системы) в случае, когда куча закончилась. +Это и будет темой четвертой лабораторной работы. + + + + + + + + +* Задание 3 + +В качестве последнего задания на 2 балла вы можете выбрать одно из двух заданий. + +** Первый вариант + +Первый вариант задания - это развитие принтера, который вы увидели на прошлом семинаре. +Добавьте туда: + +- вычислитель, который умеет вычислять формулы. Сделайте его расширяемым, так же, как сделан принтер. Подсказка: в отличие от принтера, который не имеет состояния, для вычисления потребуется накапливать состояние, поэтому функции будут иметь больше аргументов, нежели принтеры для узлов. +- парсер, который сможет распознавать верные формулы из сложения, умножения, деления и вычитания. Не забудьте про скобки! +- принтер, который будет выводить выражение используя постфиксную запись (обратная польская запись, без использования скобок). + +В качестве стартовой точки для выполнения этого задания можете использовать расширенный вариант принтера ([[./ast.h][ast.h]], [[./ast.c][ast.c]], [[./main.c][main.c]], [[./makefile][makefile]]), +в который уже включен базовый токенайзер ([[./tokenizer.h][tokenizer.h]], [[./tokenizer.c][tokenizer.c]]), а также реализация стека и очереди для абстракнтых типов ([[./ring.h][ring.h]]). + + +** Второй вариант + +Второй вариант задания - это реализация несложной структуры данных как абстрагированного модуля с непрозрачным типом. Ему посвящена эта заметка. + +*Изначальный код* + + У вас есть код внутри одной функции =main=, который реализует расширяемый массив (вектор). + Изучите его. + +#+begin_src c +/* bad.c */ + +#include +#include +#include + +int main() { + int64_t *array = malloc(sizeof(int64_t) * 5); + // вместимость -- сколько памяти выделено + size_t capacity = 5; + // количество -- сколько памяти по факту используется из выделенной. + size_t count = 0; + // заполните массив квадратами чисел от 0 до 100 + // если не хватает места, расширяем в два раза + for (size_t i = 0; i <= 100; i++) { + if (count == capacity) { + array = realloc(array, sizeof(int64_t) * capacity * 2); + capacity = capacity * 2; + } + array[count++] = i * i; + } + + for (size_t i = 0; i < 100; i++) { + printf("%" PRId64 " ", array[i]); + } + return 0; +} +#+end_src + + Расширяемый массив в отличие от обычного имеет нефиксированный размер, в конец такого массива можно добавлять элементы. + Как это работает: + - Мы выделяем память с запасом. + - Мы храним два дополнительных числа: количество выделенных слотов под элементы и количество заполненных слотов в массиве. + - Пока у нас хватает выделенных слотов, мы просто дописываем элементы в массив, увеличивая количество занятых слотов. + - Если слотов перестало хватать, то увеличиваем количество слотов в 2 раза (или линейно на некоторый фиксированный размер). + Для этого используем =realloc= чтобы скопировать выделенную память в расширенный участок. + + *Вопрос* Прочитайте раздел =man malloc= про функцию =realloc=. + +*Задание (второй вариант)* + + + Ваша задача --- выделить из этого кода как минимум модуль с реализацией вектора, снабжённый заголовочным файлом. + + - Вектор должен быть реализован как [[https://stepik.org/lesson/408352/step/6][непрозрачная структура данных]]. + - Доступ к его элементам должен быть контролируем и осуществляться через getter и setter. + - Постарайтесь максимально переиспользовать код и ничего не дублировать. + - Вывод вектора реализуйте как отдельную функцию, которая принимает =FILE*=, в который нужно вывести его содержимое. + Эту функцию можно также разбить на функцию =foreach= и принтер одного элемента. + - Стремитесь сделать настолько маленькие функции, насколько возможно. + + Ваша реализацяия как минимум должна позволять: + - Получить доступ к любому элементу. + - Получить информацию о текущей длинне массива и количестве выделенной памяти. + - Добавить элемент в конец массива. + - Добавить другой массив в конец массива (скопировать данные). + - Изменить размер массива на заданный (при необхоимости выделить память). + - Изменить размер массива на меньший с освобождением неиспользуемой памяти. + - Освободить память. + - Вывести массив в указанный поток вывода. + + В результате должна получиться программа из нескольких файлов, которая делает то же самое, но в которой =main= содержит только заполнение вектора числами и вызов функции, печатающей его в =stdout=. + + Прочитайте заметку [[[https://gitlab.se.ifmo.ru/c-language/main/-/wikis/%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0-%D1%81%D1%82%D0%B8%D0%BB%D1%8F-%D0%BD%D0%B0%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D1%8F-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC-%D0%BD%D0%B0-C][Правила хорошего стиля]]] --- ваш код должен им соответствовать. + diff --git a/sem6/ast.c b/sem6/ast.c new file mode 100644 index 0000000..c6940d7 --- /dev/null +++ b/sem6/ast.c @@ -0,0 +1,77 @@ +/* ast.c */ + +#include + +#include "ast.h" + +struct AST *newnode(struct AST ast) { + struct AST *const node = malloc(sizeof(struct AST)); + *node = ast; + return node; +} + +struct AST _lit(int64_t value) { + return (struct AST){AST_LIT, .as_literal = {value}}; +} + +struct AST *lit(int64_t value) { + return newnode(_lit(value)); +} +struct AST _unop(enum unop_type type, struct AST *operand) { + return (struct AST){AST_UNOP, .as_unop = {type, operand}}; +} + +struct AST *unop(enum unop_type type, struct AST *operand) { + return newnode(_unop(type, operand)); +} + +struct AST _binop(enum binop_type type, struct AST *left, struct AST *right) { + return (struct AST){AST_BINOP, .as_binop = {type, left, right}}; +} +struct AST *binop(enum binop_type type, struct AST *left, struct AST *right) { + return newnode(_binop(type, left, right)); +} + +static const char *BINOPS[] = { + [BIN_PLUS] = "+", [BIN_MINUS] = "-", [BIN_MUL] = "*", [BIN_DIV] = "/" }; +static const char *UNOPS[] = {[UN_NEG] = "-"}; + +typedef void(printer)(FILE *, struct AST *); + + +static void print_binop(FILE *f, struct AST *ast) { + fprintf(f, "("); + print_ast(f, ast->as_binop.left); + fprintf(f, ")"); + fprintf(f, "%s", BINOPS[ast->as_binop.type]); + fprintf(f, "("); + print_ast(f, ast->as_binop.right); + fprintf(f, ")"); +} +static void print_unop(FILE *f, struct AST *ast) { + fprintf(f, "%s(", UNOPS[ast->as_unop.type]); + print_ast(f, ast->as_unop.operand); + fprintf(f, ")"); +} +static void print_lit(FILE *f, struct AST *ast) { + fprintf(f, "%" PRId64, ast->as_literal.value); +} + +static printer *ast_printers[] = { + [AST_BINOP] = print_binop, [AST_UNOP] = print_unop, [AST_LIT] = print_lit }; + +void print_ast(FILE *f, struct AST *ast) { + if (ast) + ast_printers[ast->type](f, ast); + else + fprintf(f, ""); +} + +int64_t calc_ast(struct AST *ast) { + /* TODO */ + return 0; +} + +void p_print_ast(FILE *f, struct AST *ast) { + /* TODO */ +} diff --git a/sem6/ast.h b/sem6/ast.h new file mode 100644 index 0000000..9d11657 --- /dev/null +++ b/sem6/ast.h @@ -0,0 +1,56 @@ +/* ast.h */ + +#pragma once +#ifndef _LLP_AST_H_ +#define _LLP_AST_H + +#include +#include + +struct AST { + enum AST_type { AST_BINOP, AST_UNOP, AST_LIT } type; + union { + struct binop { + enum binop_type { BIN_PLUS, BIN_MINUS, BIN_MUL, BIN_DIV } type; + struct AST *left, *right; + } as_binop; + struct unop { + enum unop_type { UN_NEG } type; + struct AST *operand; + } as_unop; + struct literal { + int64_t value; + } as_literal; + }; +}; + +struct AST *newnode(struct AST ast); +struct AST _lit(int64_t value); +struct AST *lit(int64_t value); +struct AST _unop(enum unop_type type, struct AST *operand); +struct AST *unop(enum unop_type type, struct AST *operand); +struct AST _binop(enum binop_type type, struct AST *left, struct AST *right); +struct AST *binop(enum binop_type type, struct AST *left, struct AST *right); + +#define DECLARE_BINOP(fun, code) \ +static struct AST *fun(struct AST *left, struct AST *right) { \ + return binop(BIN_##code, left, right); \ +} +DECLARE_BINOP(add, PLUS) +DECLARE_BINOP(mul, MUL) +DECLARE_BINOP(sub, MINUS) +DECLARE_BINOP(divide, DIV) +#undef DECLARE_BINOP + +#define DECLARE_UNOP(fun, code) \ +static struct AST *fun(struct AST *operand) { \ + return unop(UN_##code, operand); \ +} +DECLARE_UNOP(neg, NEG) +#undef DECLARE_UNOP + +void print_ast(FILE *f, struct AST *ast); +int64_t calc_ast(struct AST *ast); +void p_print_ast(FILE *f, struct AST *ast); + +#endif diff --git a/sem6/ast.o b/sem6/ast.o new file mode 100644 index 0000000..c0efedb Binary files /dev/null and b/sem6/ast.o differ diff --git a/sem6/bad.c b/sem6/bad.c new file mode 100644 index 0000000..ad7a9bf --- /dev/null +++ b/sem6/bad.c @@ -0,0 +1,27 @@ +/* bad.c */ + +#include +#include +#include + +int main() { + int64_t *array = malloc(sizeof(int64_t) * 5); + // вместимость -- сколько памяти выделено + size_t capacity = 5; + // количество -- сколько памяти по факту используется из выделенной. + size_t count = 0; + // заполните массив квадратами чисел от 0 до 100 + // если не хватает места, расширяем в два раза + for (size_t i = 0; i <= 100; i++) { + if (count == capacity) { + array = realloc(array, sizeof(int64_t) * capacity * 2); + capacity = capacity * 2; + } + array[count++] = i * i; + } + + for (size_t i = 0; i < 100; i++) { + printf("%" PRId64 " ", array[i]); + } + return 0; +} diff --git a/sem6/heap-0.c b/sem6/heap-0.c new file mode 100644 index 0000000..446c725 --- /dev/null +++ b/sem6/heap-0.c @@ -0,0 +1,91 @@ +/* heap-0.c */ + +#include +#include +#include +#include + +#define heap_blocks 16 +#define block_capacity 1024 + +struct heap { + struct block { + char contents[block_capacity]; + } blocks[heap_blocks]; + bool is_occupied[heap_blocks]; +} global_heap = {0}; + +struct block_id { + size_t value; + bool valid; + struct heap* heap; +}; + +struct block_id block_id_new(size_t value, struct heap* from) { + return (struct block_id){.valid = true, .value = value, .heap = from}; +} +struct block_id block_id_invalid() { return (struct block_id){.valid = false}; } + +bool block_id_is_valid(struct block_id bid) { + return bid.valid && bid.value < heap_blocks; +} +/* find block */ + +bool block_is_free(struct block_id bid) { + return bid.valid && bid.heap->is_occupied[bid.value]; +} + +/* allocate */ +/* find a free block, reserve it and return its id */ +struct block_id block_allocate(struct heap* heap) { + for (size_t i = 0; i < heap_blocks; i++) { + bool* block_occupied = &(heap->is_occupied[i]); + if (!*block_occupied) { + *block_occupied = true; + return block_id_new(i, true, heap); + } + } + return block_id_invalid(); +} + +/* mark block as 'free' */ +void block_free(struct block_id b) { + if (b.valid) b.heap->is_occupied[b.value] = false; +} + +/* printer */ +const char* block_repr(struct block_id b) { + static const char* const repr[] = {[false] = " .", [true] = " ="}; + if (b.valid) + return repr[b.heap->is_occupied[b.value]]; + else + return "x"; +} + +void block_debug_info(struct block_id b, FILE* f) { + fprintf(f, "%s", block_repr( b)); +} + +void block_foreach_printer(struct heap* h, size_t count, + void printer(struct block_id, FILE* f), + FILE* f) { + for (size_t c = 0; c < count; c++) + printer(block_id_new(c,h), f); +} + +void heap_debug_info(struct heap* h, FILE* f) { + block_foreach_printer(h, heap_blocks, block_debug_info, f); + fprintf(f, "\n"); +} +/* -------- */ + +int main() { + heap_debug_info(&global_heap, stdout); + block_allocate(&global_heap); + struct block_id bid = block_allocate(&global_heap); + block_allocate(&global_heap); + + block_free(bid); + heap_debug_info(&global_heap, stdout); + return 0; +} diff --git a/sem6/heap-0.exe b/sem6/heap-0.exe new file mode 100644 index 0000000..7c378c2 Binary files /dev/null and b/sem6/heap-0.exe differ diff --git a/sem6/heap-1.c b/sem6/heap-1.c new file mode 100644 index 0000000..bbba2b4 --- /dev/null +++ b/sem6/heap-1.c @@ -0,0 +1,212 @@ +/* heap-1.c */ + +#include +#include +#include +#include + +#define HEAP_BLOCKS 16 +#define BLOCK_CAPACITY 1024 + +enum block_status { BLK_FREE = 0, BLK_ONE, BLK_FIRST, BLK_CONT, BLK_LAST }; + +struct heap { + struct block { + char contents[BLOCK_CAPACITY]; + } blocks[HEAP_BLOCKS]; + enum block_status status[HEAP_BLOCKS]; +} global_heap = {0}; + +struct block_id { + size_t value; + bool valid; + struct heap* heap; +}; + +struct block_id block_id_new(size_t value, struct heap* from) { + return (struct block_id){.valid = true, .value = value, .heap = from}; +} +struct block_id block_id_invalid() { + return (struct block_id){.valid = false}; +} + +bool block_id_is_valid(struct block_id bid) { + return bid.valid && bid.value < HEAP_BLOCKS; +} + +/* Find block */ + +bool block_is_free(struct block_id bid) { + if (!block_id_is_valid(bid)) + return false; + return bid.heap->status[bid.value] == BLK_FREE; +} + +/* Allocate */ +struct block_id block_allocate(struct heap* heap, size_t size) { + if (size <= 0) return block_id_invalid(); + enum block_status* first_status = NULL; + enum block_status* last_status = NULL; + for (size_t i = 0; i < HEAP_BLOCKS; i++) { + if (i + size > HEAP_BLOCKS) return block_id_invalid(); + first_status = &(heap->status[i]); + if (*first_status != BLK_FREE) continue; + bool not_enough_space = false; + for (size_t j = i + 1; j < i + size; j++) { + last_status = &(heap->status[j]); + if (*last_status != BLK_FREE) { + not_enough_space = true; + break; + } + } + if (not_enough_space) continue; + if (size == 1) *first_status = BLK_ONE; + else { + *first_status = BLK_FIRST; + *last_status = BLK_LAST; + for (size_t j = i + 1; j < i + size - 1; j++) + heap->status[j] = BLK_CONT; + } + return block_id_new(i, heap); + } + return block_id_invalid(); +} + +void heap_debug_info(struct heap*, FILE*); + +/* Free */ +void block_free(struct block_id b) { + if (!b.valid) return; + if (b.heap->status[b.value] == BLK_FREE) return; + bool is_last = b.heap->status[b.value] == BLK_ONE; + b.heap->status[b.value] = BLK_FREE; + for (size_t i = b.value + 1; !is_last; i++) { + is_last = b.heap->status[i] == BLK_LAST; + b.heap->status[i] = BLK_FREE; + } +} + +/* Printer */ +const char* block_repr(struct block_id b) { + static const char* const repr[] = {[BLK_FREE] = " .", + [BLK_ONE] = " *", + [BLK_FIRST] = "[=", + [BLK_LAST] = "=]", + [BLK_CONT] = " ="}; + if (b.valid) + return repr[b.heap->status[b.value]]; + else + return "INVALID"; +} + +void block_debug_info(struct block_id b, FILE* f) { + fprintf(f, "%s", block_repr(b)); +} + +void block_foreach_printer(struct heap* h, size_t count, + void printer(struct block_id, FILE* f), FILE* f) { + for (size_t c = 0; c < count; c++) + printer(block_id_new(c, h), f); +} + +void heap_debug_info(struct heap* h, FILE* f) { + block_foreach_printer(h, HEAP_BLOCKS, block_debug_info, f); + fprintf(f, "\n"); +} +/* -------- */ + +void heap_free(struct heap* heap) { + for (size_t i = 0; i < HEAP_BLOCKS; i++) + heap->status[i] = BLK_FREE; +} + +void allocate_block_test(struct heap* heap) { + printf("allocate_block_test: "); + block_allocate(heap, 1); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void allocate_big_block_test(struct heap* heap) { + printf("allocate_big_block_test: "); + block_allocate(heap, 5); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void allocate_multiple_blocks_test(struct heap* heap) { + printf("allocate_multiple_blocks_test: "); + block_allocate(heap, 7); + block_allocate(heap, 1); + block_allocate(heap, 3); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void allocate_more_than_available_test(struct heap* heap) { + printf("allocate_more_than_available_test: "); + block_allocate(heap, 17); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void allocate_limit_test(struct heap* heap) { + printf("allocate_limit_test: "); + block_allocate(heap, 16); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void allocate_middle_test(struct heap* heap) { + printf("allocate_middle_test: "); + block_allocate(heap, 5); + struct block_id id = block_allocate(heap, 3); + block_allocate(heap, 7); + block_free(id); + block_allocate(heap, 2); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void free_block_test(struct heap* heap) { + printf("free_block_test: "); + struct block_id id = block_allocate(heap, 1); + block_free(id); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void free_big_block_test(struct heap* heap) { + printf("free_big_block_test: "); + struct block_id id = block_allocate(heap, 5); + block_free(id); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +void free_multiple_blocks_test(struct heap* heap) { + printf("free_multiple_blocks_test: "); + struct block_id id1 = block_allocate(heap, 7); + struct block_id id2 = block_allocate(heap, 1); + struct block_id id3 = block_allocate(heap, 5); + block_free(id1); + block_free(id2); + block_free(id3); + heap_debug_info(heap, stdout); + heap_free(heap); +} + +int main() { + printf("\n"); + allocate_block_test(&global_heap); + allocate_big_block_test(&global_heap); + allocate_multiple_blocks_test(&global_heap); + allocate_more_than_available_test(&global_heap); + allocate_limit_test(&global_heap); + allocate_middle_test(&global_heap); + free_block_test(&global_heap); + free_big_block_test(&global_heap); + free_multiple_blocks_test(&global_heap); + printf("\n"); + return 0; +} diff --git a/sem6/heap-1.exe b/sem6/heap-1.exe new file mode 100644 index 0000000..e12e3e1 Binary files /dev/null and b/sem6/heap-1.exe differ diff --git a/sem6/main.c b/sem6/main.c new file mode 100644 index 0000000..8625bd3 --- /dev/null +++ b/sem6/main.c @@ -0,0 +1,58 @@ +/* main.c */ + +#include + +#include "ast.h" +#include "ring.h" +#include "tokenizer.h" + +void ast_print(struct AST ast) { print_ast(stdout, &ast); } +void token_print(struct token token) { printf("%s(%" PRId64 ")", TOKENS_STR[token.type], token.value); } + +DECLARE_RING(ast, struct AST) +DEFINE_RING(ast, struct AST) +DEFINE_RING_PRINT(ast, ast_print) +DEFINE_RING(token, struct token) +DEFINE_RING_PRINT(token, token_print) + +#define RETURN_ERROR(code, msg) return printf(msg), code + +struct AST *build_ast(char *str) +{ + struct ring_token *tokens = NULL; + if ((tokens = tokenize(str)) == NULL) + RETURN_ERROR(NULL, "Tokenization error.\n"); + + ring_token_print(tokens); + + ring_token_free(&tokens); + + return NULL; +} + + +int main() +{ + /* char *str = "1 + 2 * (2 - -3) + 8"; */ + const int MAX_LEN = 1024; + char str[MAX_LEN]; + if (fgets(str, MAX_LEN, stdin) == NULL) + RETURN_ERROR(0, "Input is empty."); + + if (str[strlen(str) - 1] == '\n') + str[strlen(str) - 1] = '\0'; + + struct AST *ast = build_ast(str); + + if (ast == NULL) + printf("AST build error.\n"); + else + { + print_ast(stdout, ast); + printf("\n\n%s = %" PRId64 "\n", str, calc_ast(ast)); + p_print_ast(stdout, ast); + printf(" = %" PRId64 "\n", calc_ast(ast)); + } + + return 0; +} diff --git a/sem6/main.o b/sem6/main.o new file mode 100644 index 0000000..5e39faa Binary files /dev/null and b/sem6/main.o differ diff --git a/sem6/makefile b/sem6/makefile new file mode 100644 index 0000000..d7fe0b0 --- /dev/null +++ b/sem6/makefile @@ -0,0 +1,21 @@ +CFLAGS = -g -O2 -Wall -Werror -std=c17 -Wno-unused-function -Wdiscarded-qualifiers -Wincompatible-pointer-types -Wint-conversion -fno-plt +CC = gcc +LD = gcc +TARGET = parser + +all: $(TARGET) + +$(TARGET): ast.o main.o tokenizer.o + $(LD) -o $@ $^ + +%.o: %.c + $(CC) -c $(CFLAGS) -o $@ $< + +clean: + $(RM) $(TARGET) *.o + +run: + ./$(TARGET) + +.PHONY: clean all run + diff --git a/sem6/parser b/sem6/parser new file mode 100644 index 0000000..6c39230 Binary files /dev/null and b/sem6/parser differ diff --git a/sem6/ring.h b/sem6/ring.h new file mode 100644 index 0000000..ce6994f --- /dev/null +++ b/sem6/ring.h @@ -0,0 +1,144 @@ +/* ring.h */ + +#pragma once +#ifndef _LLP_RING_H_ +#define _LLP_RING_H + +#include + + +#define DECLARE_RING(name, type) \ +struct ring_##name { \ + type value; \ + struct ring_##name* next; \ + struct ring_##name* prev; \ +}; + +#define DEFINE_RING(name, type) \ +static struct ring_##name *ring_##name##_create(type value) \ +{ \ + struct ring_##name *item = malloc(sizeof(struct ring_##name)); \ + if (item == NULL) \ + return NULL; \ + item->value = value; \ + item->next = item; \ + item->prev = item; \ + return item; \ +} \ +static type ring_##name##_last(struct ring_##name *ring) \ +{ \ + if (ring == NULL) \ + return *(type *)NULL; \ + return ring->prev->value; \ +} \ +static type ring_##name##_first(struct ring_##name *ring) \ +{ \ + if (ring == NULL) \ + return *(type *)NULL; \ + return ring->value; \ +} \ +static struct ring_##name *ring_##name##_push( \ + struct ring_##name **ring, type value) \ +{ \ + if (ring == NULL) \ + return NULL; \ + struct ring_##name *item = ring_##name##_create(value); \ + if (item == NULL) \ + return NULL; \ + if (*ring == NULL) \ + { \ + *ring = item; \ + return item; \ + } \ + item->next = *ring; \ + item->prev = (*ring)->prev; \ + (*ring)->prev->next = item; \ + (*ring)->prev = item; \ + return item; \ +} \ +static type ring_##name##_pop(struct ring_##name **ring) \ +{ \ + if (ring == NULL) \ + return *(type *)NULL; \ + struct ring_##name *item = (*ring)->prev; \ + type ret = item->value; \ + if (item == *ring) \ + { \ + *ring = NULL; \ + free(item); \ + return ret; \ + } \ + item->prev->next = *ring; \ + (*ring)->prev = item->prev; \ + free(item); \ + return ret; \ +} \ +static struct ring_##name *ring_##name##_push_top( \ + struct ring_##name **ring, type value) \ +{ \ + struct ring_##name *item = ring_##name##_push(ring, value); \ + if (item == NULL) \ + return NULL; \ + *ring = item; \ + return item; \ +} \ +static type ring_##name##_pop_top(struct ring_##name **ring) \ +{ \ + if (ring == NULL) \ + return *(type *)NULL; \ + *ring = (*ring)->next; \ + return ring_##name##_pop(ring); \ +} \ +static void ring_##name##_free(struct ring_##name **ring) \ +{ \ + if (*ring == NULL) \ + return; \ + struct ring_##name *tmp; \ + (*ring)->prev->next = NULL; \ + while (*ring != NULL) \ + { \ + tmp = *ring; \ + *ring = (*ring)->next; \ + free(tmp); \ + } \ +} + +#define DEFINE_RING_PRINT(name, printer) \ +static void ring_##name##_print(struct ring_##name *ring) \ +{ \ + printf("-> "); \ + if (ring == NULL) \ + { \ + printf("NULL -> \n"); \ + return; \ + } \ + printer(ring->value); \ + struct ring_##name *next = ring->next; \ + while (next != ring) \ + { \ + printf(" -> "); \ + printer(next->value); \ + next = next->next; \ + } \ + printf(" ->\n"); \ +} \ +static void ring_##name##_print_back(struct ring_##name *ring) \ +{ \ + printf("<- "); \ + if (ring == NULL) \ + { \ + printf("NULL <- \n"); \ + return; \ + } \ + printer(ring->value); \ + struct ring_##name *prev = ring->prev; \ + while (prev != ring) \ + { \ + printf(" <- "); \ + printer(prev->value); \ + prev = prev->prev; \ + } \ + printf(" <-\n"); \ +} + +#endif diff --git a/sem6/tokenizer.c b/sem6/tokenizer.c new file mode 100644 index 0000000..90faf94 --- /dev/null +++ b/sem6/tokenizer.c @@ -0,0 +1,99 @@ +/* tokenizer.c */ + +#include +#include + +#include "ring.h" +#include "tokenizer.h" + +DEFINE_RING(token, struct token) + +static const char *SEPARATORS = " \t\n"; +static const int NUM_TOKENS = 6; +static const char *TOKENS[] = { + [TOK_PLUS] = "+", + [TOK_MINUS] = "-", + [TOK_MUL] = "*", + [TOK_DIV] = "/", + [TOK_OPEN] ="(", + [TOK_CLOSE] = ")", + [TOK_LIT] = "", + [TOK_NEG] = "-" +}; + +const char *TOKENS_STR[] = { + [TOK_PLUS] = "PLUS", + [TOK_MINUS] = "MINUS", + [TOK_MUL] = "MUL", + [TOK_DIV] = "DIV", + [TOK_OPEN] ="OPEN", + [TOK_CLOSE] = "CLOSE", + [TOK_LIT] = "LIT", + [TOK_NEG] = "NEG", + [TOK_END] = "END", + [TOK_ERROR] = "ERROR" + }; + +char *skip_separators(char *str) +{ + while (*str != '\0' && strchr(SEPARATORS, *str) != NULL) + str++; + return str; +} + +struct token next_token(char **str) +{ + int i; + char *buf = skip_separators(*str); + + if (*buf == '\0') + { + return (struct token){TOK_END, 0}; + } + + /* Serarch for an operation */ + for (i = 0; i < NUM_TOKENS; i++) + if (strncmp(buf, TOKENS[i], strlen(TOKENS[i])) == 0) + { + *str = buf + strlen(TOKENS[i]); + return (struct token){i, 0}; + } + + /* Serach for literals */ + if (isdigit(*buf)) + { + char *str_end; + int64_t tmp = strtoll(buf, &str_end, 10); + *str = str_end; + return (struct token){TOK_LIT, tmp}; + } + + return (struct token){TOK_ERROR, 0}; +} + +int is_binop(struct token token) +{ + return token.type == TOK_PLUS || token.type == TOK_MINUS || + token.type == TOK_MUL || token.type == TOK_DIV; +} + +struct ring_token *tokenize(char *str) +{ + struct token token, prev = {TOK_ERROR, 0}; + struct ring_token *tokens = NULL; + while ((token = next_token(&str)).type != TOK_END) + { + if (token.type == TOK_ERROR) + { + ring_token_free(&tokens); + return NULL; + } + if (token.type == TOK_MINUS && + (tokens == NULL || prev.type == TOK_OPEN || is_binop(prev))) + token.type = TOK_NEG; + ring_token_push(&tokens, token); + prev = token; + } + + return tokens; +} diff --git a/sem6/tokenizer.h b/sem6/tokenizer.h new file mode 100644 index 0000000..cc8091e --- /dev/null +++ b/sem6/tokenizer.h @@ -0,0 +1,25 @@ +/* tokenizer.h */ + +#pragma once +#ifndef _LLP_TOKENIZER_H_ +#define _LLP_TOKENIZER_H_ + +#include + +#include "ring.h" + +struct token { + enum token_type { + TOK_PLUS = 0, TOK_MINUS, TOK_MUL, + TOK_DIV, TOK_OPEN, TOK_CLOSE, TOK_LIT, + TOK_NEG, TOK_END, TOK_ERROR } type; + int64_t value; +}; + +DECLARE_RING(token, struct token) + +struct ring_token *tokenize(char *str); + +extern const char *TOKENS_STR[]; + +#endif diff --git a/sem6/tokenizer.o b/sem6/tokenizer.o new file mode 100644 index 0000000..b067de1 Binary files /dev/null and b/sem6/tokenizer.o differ diff --git a/sem7/README.org b/sem7/README.org new file mode 100644 index 0000000..b2d39ae --- /dev/null +++ b/sem7/README.org @@ -0,0 +1,442 @@ +#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup +#+LANG: ru + +#+TITLE: Семинар 7: Оптимизации, уязвимость стека + +В этом семинаре мы изучим некоторые оптимизации, которые производят =gcc= и другие компиляторы языка С, а также войдём в роль хакера и сломаем несколько программ. + +* Оптимизации + +** Инструменты + +Научитесь пользоваться [[http://godbolt.org]] для компиляции C и просмотра ассемблерного кода. + +*Вопрос* Как посмотреть флаги компиляции в godbolt? + +*Вопрос* Что означают флаги: =-O0=, =-O1=, =-O2=, =-Os=? + +*Вопрос* Скомпилируйте [[https://gitlab.se.ifmo.ru/programming-languages/cse-programming-languages-fall-2022/main/-/blob/master/seminar-5/printer.c][программу]] =printer.c= из семинара 5 с ключами =-O0= и =-O3= (в Godbolt можно создать две вкладки с компиляторами рядом и сравнить листинги). + + +** Volatile + +Если добавить к типу модификатор =volatile=, то действия с такими данными гарантированно будут произведены. +Если из переменной в коде есть чтение, то чтение обязательно случится, а если будет запись --- произойдёт и она. +Для остальных переменных это неверно: например, чтения переменных из памяти не обязательно произойдут, например, зачем читать из памяти константу если можно напрямую подставить её значение? + +*Вопрос* Посмотрите как с увеличением уровня оптимизаций пропадают чтения из памяти: + + +#+begin_src c +/* volatile.c */ + +#include + +void print_int(int x) { printf("%d", x); } + +int main() { + + int x = 42; + volatile int y = 42; + + print_int(x); + print_int(y); +} +#+end_src + + +*Вопрос* пометьте функцию =print_int= как =static=. Что произошло в оптимизированном коде и почему? + + +** Пролог и эпилог + +При трансляции функций нередко используются понятия /пролога/ и /эпилога/ --- шаблонных фрагментов ассемблерного кода в начале и конце функции. +Их цель --- установка регистра =rbp= так, чтобы он указывал на начало стекового фрейма, где лежат все интересные для функции данные. +Пролог устанавливает его, как правило следующей последовательностью инструкций: + +#+begin_src asm +push rbp +mov rbp, rsp +sub rsp, <сколько выделить байтов в стеке> +#+end_src + +Эпилог возвращает =rbp= в исходное состояние. Напоминаем, что =rbp= --- callee-saved регистр. + +#+begin_src asm +mov rsp, rbp ; отмотать стек в исходное состояние +pop rbp ; восстановить rbp +ret +#+end_src + +Иногда используется также специализированная инструкция =leave=. + +*Вопрос* Что делает эта инструкция? + + +** Red zone + +Указатель на вершину стека =rsp= делит память на две части: в старших адресах лежит сам стек, в младшие он растёт. +Мы привыкли к тому, что нельзя обращаться к младшей части памяти и что-то там хранить. +Однако соглашение вызова на самом деле допускает использование части "рядом" со стеком, а именно 128 байт от =rsp= в область младших адресов: + + +#+begin_src +| | +| ... | +| | +├--------┤ ← rsp-128 +| | +| red | +| zone | +| | +├---^----┤ ← rsp +| stack | +| | +#+end_src + +Чтобы использовать red zone необходимо, чтобы функция не вызывала другие функции. + +Если функция не вызывает другие функции и выделяет N байт для хранения данных в стеке, то хранить она может на самом деле N+128 байт. + +Рассмотрим следующий файл: + + +#+begin_src c +/* prologue-epilogue.c */ + +int maximum(int a, int b) { + char buffer[4096]; + buffer[0] = 0x7; + if (a < b) + return b; + return a; +} + +int main(void) { + int x = maximum(42, 999); + return 0; +} +#+end_src + + +*Вопрос* Скомпилируйте его без оптимизаций и объясните содержимое функции =maximum=. Почему =rsp= уменьшается на это число? + + +** Предподсчёт значений + +Скомпилируйте следующий код с максимальным уровнем оптимизации и объясните, откуда там берётся строка для =printf=. + + +#+begin_src c +/* precompute.c */ + +#include +#include + +int main (){ + char buff[1024] = {0}; + strcat(buff, "hello"); + strcat(buff, " world"); + printf("%s", buff); + +} +#+end_src + + +** Хвостовая рекурсия + +*Вопрос* Вспомните, почему пару инструкций =call= + =ret= можно заменить на =jmp=, например: + +#+begin_src asm +... +call f +ret + + +f: +... +ret + +; то же, что и: +... +jmp f + + +f: +... +ret +#+end_src + +Скомпилируйте и запустите следующий код: + +#+begin_src c +/* tail-rec.c */ + +#include +#include +#include +#include + +void print_size(size_t i) { printf("%zu" , i); } + +struct list { + int64_t elem; + struct list *next; +}; + +struct list *c(int64_t head, struct list *tail) { + struct list *h = (struct list *)malloc(sizeof(struct list)); + h->elem = head; + h->next = tail; + return h; +} + +size_t list_length(struct list const *l) { + if (!l) + return 0; + return 1 + list_length(l->next); +} + +int main(int argc, char **argv) { + const size_t len = 1024 * 1024; + + struct list *lst = NULL; + + for( size_t i = 0; i < len; i++) { + lst = c(i, lst); + } + + print_size(list_length(lst)); + return 0; +} +#+end_src + +Что выведется на экран? Объясните это поведение. + +*Задание 1* Как можно переписать функцию (какую?) чтобы программа корректно считала длину длинного списка? + + +** Copy elision + +Скомпилируйте следующий код с максимальным уровнем оптимизации. + +#+begin_src c +/* return-value.c */ + +#include + +struct string_buffer { + char data[1024]; +}; + +__attribute__((noinline)) struct string_buffer sb_init() { + return (struct string_buffer){.data = "hey"}; +} + +volatile struct string_buffer sb; +int main() { + sb = sb_init(); + printf("%s", sb.data); + return 0; +} +#+end_src + +Объясните, зачем в функцию =sb_init= передаётся аргумент, хотя по сигнатуре у неё параметров нет. + +** Restrict + +Скомпилируйте следующий код с максимальным уровнем оптимизации. + +#+begin_src c +/* restrict-0.c */ + +void f(int *x, int *add) { + *x += *add; + *x += *add; +} +#+end_src + +Эта функция прибавляет к первому аргументу второй два раза; оба аргумента являются указателями на числа. +Мы могли бы прибавить к первому аргументу удвоенное значение второго и это было бы быстрее. + +Посмотрите внимательно на ассемблерную функцию; есть ли там эта оптимизация? Если да, то почему она верна, если нет, то почему неверна? + +Модифицируйте код следующим образом: + +#+begin_src c +/* restrict-1.c */ + +void f(int *restrict x, int *restrict add) { + *x += *add; + *x += *add; +} +#+end_src + +Как изменится скомпилированный код с оптимизациями? +Прочитайте стр. 281--282 в "Low-level programming" смысл ключевого слова =restrict= и объясните его влияние на код. + + + + + + + + + + + +* Smash this stack + + +** Уязвимость форматного вывода + + +*Вопрос* Как в функцию передаются следующие аргументы после шестого? + + +Скомпилируйте эту программу. + +#+begin_src c +/* printf.c */ + +#include + +int main(void) { + char buffer[1024]; + fgets( buffer, 1024, stdin); + printf( buffer ); + return 0; +} +#+end_src + +Запустите её, передавая ей строчки вида ="%x %x"=, ="%x %x %x"= и т.д. +Что это за числа? + + +Прочтите стр. 285--287 в "Low-level programming". + + +* Перезапись адреса возврата + +Напомним, что адрес возврата лежит в стеке на границе стекового фрейма, сразу после сохранённого значения =rbp= (если оно сохраняется). + + +*Вопрос* Что такое ASLR (address space layout randomization)? + +Отключите ASLR следующей командой: + +#+begin_src +echo 0 | sudo tee /proc/sys/kernel/randomize_va_space +#+end_src + +Рассмотрим следующий код. + +#+begin_src c +/* stack-smash.c */ + +#include +#include + +struct user { + const char *name, *password; +} const users[] = {{"Cat", "Meowmeow"}, {"Skeletor", "Nyarr"}}; + +void print_users() { + printf("Users:\n"); + for (size_t i = 0; i < sizeof(users) / sizeof(struct user); i++) { + printf("%s: %s\n", users[i].name, users[i].password); + } +} + +void fill(FILE *f, char *where) { + size_t read_total = 0; + for (;;) { + size_t read = fread(where + read_total, 1, 1, f); + if (!read) + break; + else + read_total += read; + } +} + +void vulnerable(FILE *f) { + char buffer[8]; + fill(f, buffer); +} + +int main(int argc, char **argv) { + vulnerable(stdin); + + puts("nothing happened"); +} +#+end_src + +Скомпилируйте его вот так (это отключает некоторые механизмы защиты): + +#+begin_src bash +gcc -fno-stack-protector -z execstack -no-pie -g -o stack-smash stack-smash.c +#+end_src + +Программа принимает на вход символы, записывает их в стековый буфер и ничего с ними не делает, выводя =Nothing happened=. +Но в ней есть интересная злоумышленнику функция, которая печатает содержимое базы пользователей, в том числе их пароли. + +Злоумышленник может воспользоваться тем, что программист не проверяет, насколько много данных прислал злоумышленник и влезут ли они в буфер. +Если же они не влезут, то программа написана так, что начнут перезаписываться... сохранённые =rbp= и адрес возврата. + +Злоумышленник может подавать на вход программе любые символы. +Если вам необходимо передать нулевые символы или символы с необычными кодами, вы можете использовать =echo= вот так: + + +#+begin_src +echo -n -e "\x11\x40\x00\x99" # четыре байта с кодами 11 40 0 и 99 (16-ричными) +#+end_src + + +*Задание 2* Попробуйте переписать адрес возврата так, чтобы вместо возвращения из =vulnerable= в =main= запустить функцию =print_users=. +Программа может аварийно завершиться, главное -- чтобы функция отработала и вывела на экран список пользователей и их паролей. + +*Задание 3* Исправьте уязвимость. + +[[img/output.png]] + +Вы не можете переписывать программу, можете только подавать ей на вход разные данные. +Вы *можете* изучать скомпилированный файл с помощью =gdb=, запускать его, смотреть содержимое памяти. +Также можно пользоваться =objdump= или =readelf=, =nm= и любыми иными средствами для узнавания адреса =print_users=. +Не забывайте, что он может меняться после каждой перекомпиляции! + +Также не забудьте, что в памяти многобайтовые числа, в том числе адреса, хранятся в соответствии с Little Endian. + +** Уязвимость форматного ввода + +Аналогичная уязвимость присутствует и при чтении строк привычной многим функцией =scanf= или =fscanf=. Рассмотрим следующий код: + +#+begin_src c +/* check-pwd.c */ + +#include +#include +#include + + +int check_password(FILE *f, const char *password) { + char buffer[10]; + int okay = 0; + fscanf(f, "%s", buffer); + if (strcmp(buffer, password) == 0) + okay = 1; + + return okay; +} + +int main(int argc, char **argv) { + if (check_password(stdin, "password")) + puts("Access granted."); + else + puts("Wrong password."); +} +#+end_src + +Мы читаем пароль пароль используя функцию =fscanf= и спецификатор =%s= в буфер =buffer= никак не ограничивая количество читаемых символов. +Далее прочитанный пароль сравнивается с сохраненным и устанавливается флаг =okay=. При переполнении буффера может произойти замена значаения флага и пароль будет считаться введенным верно. + +*Задание 4* Исправьте данный код так, чтобы исключить потенциальную уязвимость. diff --git a/sem7/a.out b/sem7/a.out new file mode 100644 index 0000000..e69de29 diff --git a/sem7/check-pwd.c b/sem7/check-pwd.c new file mode 100644 index 0000000..6941e40 --- /dev/null +++ b/sem7/check-pwd.c @@ -0,0 +1,23 @@ +/* check-pwd.c */ + +#include +#include +#include + + +int check_password(FILE *f, const char *password) { + char buffer[10]; + int okay = 0; + fscanf(f, "%s", buffer); + if (strcmp(buffer, password) == 0) + okay = 1; + + return okay; +} + +int main(int argc, char **argv) { + if (check_password(stdin, "password")) + puts("Access granted."); + else + puts("Wrong password."); +} diff --git a/sem7/img/output.png b/sem7/img/output.png new file mode 100644 index 0000000..0818957 Binary files /dev/null and b/sem7/img/output.png differ diff --git a/sem7/precompute.c b/sem7/precompute.c new file mode 100644 index 0000000..07addd5 --- /dev/null +++ b/sem7/precompute.c @@ -0,0 +1,13 @@ +/* precompute.c */ + +#include +#include + +int main (){ + char buff[1024] = {0}; + strcat(buff, "hello"); + strcat(buff, " world"); + printf("%s", buff); + +} + diff --git a/sem7/printf.c b/sem7/printf.c new file mode 100644 index 0000000..3a01717 --- /dev/null +++ b/sem7/printf.c @@ -0,0 +1,11 @@ +/* printf.c */ + +#include + +int main(void) { + char buffer[1024]; + fgets( buffer, 1024, stdin); + printf( buffer ); + return 0; +} + diff --git a/sem7/prologue-epilogue.c b/sem7/prologue-epilogue.c new file mode 100644 index 0000000..6fc4d90 --- /dev/null +++ b/sem7/prologue-epilogue.c @@ -0,0 +1,15 @@ +/* prologue-epilogue.c */ + +int maximum(int a, int b) { + char buffer[4096]; + buffer[0] = 0x7; + if (a < b) + return b; + return a; +} + +int main(void) { + int x = maximum(42, 999); + return 0; +} + diff --git a/sem7/restrict-0.c b/sem7/restrict-0.c new file mode 100644 index 0000000..bbac59c --- /dev/null +++ b/sem7/restrict-0.c @@ -0,0 +1,7 @@ +/* restrict-0.c */ + +void f(int *x, int *add) { + *x += *add; + *x += *add; +} + diff --git a/sem7/restrict-1.c b/sem7/restrict-1.c new file mode 100644 index 0000000..e2f0e2d --- /dev/null +++ b/sem7/restrict-1.c @@ -0,0 +1,7 @@ +/* restrict-1.c */ + +void f(int *restrict x, int *restrict add) { + *x += *add; + *x += *add; +} + diff --git a/sem7/return-value.c b/sem7/return-value.c new file mode 100644 index 0000000..77805e2 --- /dev/null +++ b/sem7/return-value.c @@ -0,0 +1,19 @@ +/* return-value.c */ + +#include + +struct string_buffer { + char data[1024]; +}; + +__attribute__((noinline)) struct string_buffer sb_init() { + return (struct string_buffer){.data = "hey"}; +} + +volatile struct string_buffer sb; +int main() { + sb = sb_init(); + printf("%s", sb.data); + return 0; +} + diff --git a/sem7/stack-smash b/sem7/stack-smash new file mode 100644 index 0000000..13c9936 Binary files /dev/null and b/sem7/stack-smash differ diff --git a/sem7/stack-smash.c b/sem7/stack-smash.c new file mode 100644 index 0000000..af5d17e --- /dev/null +++ b/sem7/stack-smash.c @@ -0,0 +1,46 @@ +/* stack-smash.c */ + +#include +#include + +#define BUFFER_SIZE 8 + +struct user { + const char *name, *password; +} const users[] = {{"Cat", "Meowmeow"}, {"Skeletor", "Nyarr"}}; + +void print_users() { + printf("Users:\n"); + for (size_t i = 0; i < sizeof(users) / sizeof(struct user); i++) { + printf("%s: %s\n", users[i].name, users[i].password); + } +} + +void fill(FILE *f, char *where, size_t const limit) { + size_t read_total = 0; + for (;; ) { + size_t read = fread(where + read_total, 1, 1, f); + if (!read) return; + read_total += read; + } +} + +// void fill(FILE *f, char *where, size_t const limit) { +// size_t read_total = 0; +// for (;;) { +// size_t read = fread(where + read_total, 1, 1, f); +// if (!read || where[read_total] == '\n') return; +// read_total += read; +// } +// } + +void vulnerable(FILE *f) { + char buffer[BUFFER_SIZE]; + fill(f, buffer, BUFFER_SIZE); +} + +int main(int argc, char **argv) { + vulnerable(stdin); + + puts("nothing happened"); +} diff --git a/sem7/tail-rec.c b/sem7/tail-rec.c new file mode 100644 index 0000000..a5a95de --- /dev/null +++ b/sem7/tail-rec.c @@ -0,0 +1,40 @@ +/* tail-rec.c */ + +#include +#include +#include +#include + +void print_size(size_t i) { printf("%zu" , i); } + +struct list { + int64_t elem; + struct list *next; +}; + +struct list *c(int64_t head, struct list *tail) { + struct list *h = malloc(sizeof(struct list)); + h->elem = head; + h->next = tail; + return h; +} + +size_t list_length(struct list const *l) { + size_t i = 0; + while(l != NULL) i++, l = l->next; + return i; +} + +int main(int argc, char **argv) { + const size_t len = 1024 * 1024; + + struct list *lst = NULL; + + for( size_t i = 0; i < len; i++) { + lst = c(i, lst); + } + + print_size(list_length(lst)); + return 0; +} + diff --git a/sem7/tail-rec.exe b/sem7/tail-rec.exe new file mode 100644 index 0000000..0abd4d6 Binary files /dev/null and b/sem7/tail-rec.exe differ diff --git a/sem7/volatile.c b/sem7/volatile.c new file mode 100644 index 0000000..f5552cd --- /dev/null +++ b/sem7/volatile.c @@ -0,0 +1,15 @@ +/* volatile.c */ + +#include + +void print_int(int x) { printf("%d", x); } + +int main() { + + int x = 42; + volatile int y = 42; + + print_int(x); + print_int(y); +} + diff --git a/sem8/README.org b/sem8/README.org new file mode 100644 index 0000000..2f46c61 --- /dev/null +++ b/sem8/README.org @@ -0,0 +1,448 @@ +#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup +#+INCLUDE: "../common/org-header.org" +#+TITLE: Семинар 8: Процессы, взаимодействие процессов через общую память, конвейеры, многопоточность, модели памяти + + + Сегодня мы познакомимся с многопоточностью, общей памятью и с тем, какие эффекты вносит слабая модель памяти. + + Процессы изолируют программы друг от друга; каждая из них получает своё виртуальное адресное пространство и ничего не знает про другие программы. + Однако процессам иногда необходимо общаться. Набор средств для общения между процессами достаточно широк: + + - Общие файлы + - Общая память + - Конвейеры (pipes), именованные и неименованные + - Очереди сообщений + - Сокеты + - Сигналы + +* Создание новых процессов, fork + Прежде всего необходимо понять механизм создания новых процессов. Для этого служит системный вызов =fork=, создающий точную копию процесса. Затем вместо копии мы можем заменить образ приложения с помощью вызова =execve=. + + Если же нам нужно просто сделать копию родительского процесса, которая ведёт себя немного по-другому, =execve= даже не нужен. + + *Вопрос* разберите этот исходный файл. + + #+BEGIN_SRC c + /* fork-example.c */ + + #include + #include + + int main() { + // pid_t это, как и int, численный тип для идентификаторов процессов + pid_t pid = fork(); + // в зависимости от возвращаемого значения, которое попадёт в pid, + // мы поймём, находимся ли мы в родительском процессе или в дочернем. + if (pid == 0) { + printf("I am a child, pid was %d\n", pid); + printf("Child's pid is %d\n", getpid()); + } + else { + printf("I am a parent, pid was %d\n", pid); + printf("Parent's pid is %d\n", getpid()); + } + } + #+END_SRC + + *Вопрос* что именно возвращает =fork()= в родительском процессе? А что в дочернем? См. =man fork=. + + + +* Создание разделённой памяти + + Общую память можно использовать через =mmap=, с которым мы познакомились на семинаре 4. + + Рассмотрим пример создания области памяти, которая разделена между процессами. + + *Вопрос* изучите данную программу. Скомпилируйте её, запустите. Проверьте правильность PID дочернего процесса с помощью =pstree= или иными способами. Изучите содержимое =/proc/PID/maps= для родительского и дочернего процессов, найдите общую область памяти. + + #+BEGIN_SRC c + /* fork-example-1.c */ + + #include + #include + #include + #include + #include + + void* create_shared_memory(size_t size) { + return mmap(NULL, + size, + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, + -1, 0); + } + + + int main() { + void* shmem = create_shared_memory(128); + + printf("Shared memory at: %p\n" , shmem); + int pid = fork(); + + if (pid == 0) { + while (1); + } else { + printf("Child's pid is: %d\n", pid); + while(1); + } + } + #+END_SRC + + Наконец, попробуем что-то записать в эту память! Для этого нам, вообще говоря, необходимо синхронизировать родительский и дочерний процесс с помощью мьютекса. + В целях простоты мы пока сделаем код, который *В ПРИНЦИПЕ НЕПРАВИЛЬНЫЙ*, так как не имеет синхронизации. Однако он продемонстрирует обмен информацией между процессами через память. + + + *Задание 1* модифицируйте программу выше следующим образом: + - Необходимо выделить память для 10 чисел типа =int= и сделать её общей для родительского и дочернего процессов. Внесите туда числа от 1 до 10. + - Родительский процесс будет ждать завершения дочернего процесса с помощью =wait(NULL)=. После этого он должен вывести все 10 чисел на экран. + - Дочерний процесс считывает два числа с помощью =scanf=: индекс в массиве и новое значение. Он меняет соответствующее число в массиве и завершает свою работу. + + +* Конвейеры (pipes) + +Другим способом обмена данными между потоками являются конвейеры. Конвейер создается с помощью функции =pipe=. +Конвейер --- это пара дескрипторов файлов, один из них предназначен только для записи данных (номер 1), второй только для чтения (номер 0). +Все данные, записанные в дескриптор =1= буферизируются и становятся доступны для чтения по дескриптору =2=. + +#+BEGIN_SRC c + int pipe_fd[2]; + pipe(pipe_fd); +#+END_SRC + +Все необходимые конвейеры должны быть созданы до вызова =fork=, тогда они будут доступны как в родительском, так и в дочернем процессе. Если мы хотим отправлять данные в обе стороны (от родителя ребенку и обратно), то следет создать пару конвейеров. После вызова =fork= и родительский и дочерний процессы наследуют все дескпиторы конвейеров, поэтому нужно закрыть ненужные дескрипторы, используя функцию =close=. Далее мы можем передевать данные посредством конвейера между процессами: писать в один конец конвейера, используя функцию =write=, и читать и другого конца, используя функцию =read=. + +#+BEGIN_SRC c + /* pipe-example.c */ + + #include + #include + #include + + int main() { + // Создадим два конвейера + int pipes[2][2]; + pipe(pipes[0]); + pipe(pipes[1]); + // Создадим дочерний процесс + pid_t pid = fork(); + if (pid == 0) { + // Сохраним нужные дескпиторы конвейеров + int to_parent_pipe = pipes[1][1]; + int from_parent_pipe = pipes[0][0]; + // И закроем ненужные + close(pipes[1][0]); + close(pipes[0][1]); + // Отпавим один байт родителю + char c = 'A'; + write(to_parent_pipe, &c, 1); + // И будем ждать, пока родитель не пришлет 1 байт в ответ + while (read(from_parent_pipe, &c, 1) == 0) + ; + printf("Recieved from parent: %c\n", c); + // Закроем дескпиторы + close(to_parent_pipe); + close(from_parent_pipe); + return 0; + } + else { + // Сохраним нужные дескпиторы конвейеров + int from_child_pipe = pipes[1][0]; + int to_child_pipe = pipes[0][1]; + // И закроем ненужные + close(pipes[1][1]); + close(pipes[0][0]); + // Будем ждать, пока ребенок не пришлет 1 байт + char c; + while (read(from_child_pipe, &c, 1) == 0) + ; + printf("Recieved from child: %c\n", c); + // И отправим ответ + c++; + write(to_child_pipe, &c, 1); + // Дождемся завершения ребенка + waitpid(pid, NULL, 0); + // Закроем дескпиторы + close(from_child_pipe); + close(to_child_pipe); + return 0; + } + } +#+END_SRC + +Можно регламентировать обмен данными через конвейеры, используя фиксированный формат сообщения, состоящий из заголовка и данных произвольного размера: + +#+BEGIN_SRC c + enum + { + MESSAGE_MAGIC = 0xAFAF, // magic signature value + MAX_MESSAGE_LEN = 4096 // maximum message length + }; + struct __attribute__((packed)) message_header + { + uint16_t magic; // magic signature + uint16_t type; // type of the message + uint16_t data_len; // length of data + }; + enum + { + // maximum data length + MAX_MESSAGE_DATA_LEN = MAX_MESSAGE_LEN - sizeof(struct message_header) + }; + struct __attribute__((packed)) message + { + struct message_header header; + // payload + uint8_t data[MAX_MESSAGE_DATA_LEN]; + }; +#+END_SRC + +Тогда, отправка и получение сообщения в конвейер будут выглядеть следующим образом: + +#+BEGIN_SRC c + int send(int fd, const struct message *msg) + { + int msg_size; + /* Check if the input data is not empty */ + if (fd < 0 || msg == NULL) + return -1; + /* Calculate the message size to send */ + msg_size = sizeof(struct message_header) + msg->header.data_len; + /* Check if message payload size is valid */ + if (msg->header.data_len > MAX_MESSAGE_DATA_LEN) + return -1; + /* Write data to the output pipe (we assume it is ready) */ + if (write(fd, msg, msg_size) != msg_size) + return -2; + return 0; + } + + int receive(int fd, struct message *msg) + { + int msg_size; + /* Check if the input data is not empty */ + if (fd < 0 || msg == NULL) + return -1; + /* Try to read header */ + msg_size = read(fd, &msg->header, sizeof(struct message_header)); + if (msg_size == 0) + return 0; + /* Check header magic */ + if (msg->header.magic != MESSAGE_MAGIC) + return -2; + /* Check if message has payload */ + if (msg->header.data_len > MAX_MESSAGE_DATA_LEN) + return -2; + if (msg->header.data_len > 0) + msg_size += read(fd, &msg->data, msg->header.data_len); + /* Return number of bytes read */ + return msg_size; + } + +#+END_SRC + +*Вопрос* Рассмотрите [[./pipe-example-1.c][пример программы]], которая в дочернем потоке читает строки со входа и отправляет их родительскому процессу через конвейер. Нужно ли было в данном примере использовать специальное сообщение о завершении ввода из дочернего процесса? + +*Задание 2* Попробуйте синхронизировать процессы из *Задания 1*, используя конвейеры. Теперь дочерний процесс будет сообщать родительскому об изменении данных, отправляя сообщение по конвейеру. При получении сообщения родительский процесс должен вывести массив на экран. Дочерний процесс будт продолжать ожидать ввод от пользователя и менять эллементы массива пока не получит на вход отрицательный индекс - тогда он завершается. + +* Многопоточные приложения + +Вспомним базовые сведения о многопоточных приложениях. + +** Создание новых потоков + +Для создания новых потоков мы будем использовать POSIX Threads (Pthreads). Для этого необходимо использовать дополнииельно ключ =-pthread= при выозве =gcc=. +Новый поток создается функцией =pthread_create=, аргументы, передаваемые функции создания потока (4 аргумент) передаются вызываемой в новом потоке функции напрямую: + +#+begin_src c + /* thread-example.c */ + + void* my_thread(void* arg) + { + for(int i = 0; i < 10; i++ ) + { + printf("%s\n", arg); + sleep(1); + } + return NULL; + } + + int main() + { + pthread_t t1, t2; + pthread_create(&t1, NULL, my_thread, "Hello"); + pthread_create(&t2, NULL, my_thread, "world"); + pthread_exit( NULL ); + return 0; + } +#+end_src + +Используемая в примере функция =pthread_exit= ожидает завершения всех запущенных потоков и завершает текущий поток. Поэтому код, идущий после неё никогда не будет выполнен (если бы он там был). Для ожидания завершения рыботы некоторого потока без завершения текущего следует использовать функцию =pthread_join=. + +** Мьютексы + +Мьютекс (mutex - mutual exclutsion) --- один из вариантов синхронизации потоков, позволяющий, например, исключить одновременное использование одного ресурса различными потоками. Мьютекс может быть в одном из двух состояний --- закрытом (locked) или открытом (unlocked). + +Мьютекс создается, используя функцию =pthread_mutex_init=: + +#+begin_src c + pthread_mutex_t m; + pthread_mutex_init(&m, NULL); +#+end_src + +Далее мьютекс можно закрыть, используя =pthread_mutex_lock=, и открыть, используя =pthread_mutex_unlock=: + +#+begin_src c + pthread_mutex_lock(&m); + // Тут можно спокойно использовать общий ресурс + pthread_mutex_unlock(&m); +#+end_src + +Для освобождения (удаления) мьютекса следует использовать функцию =pthread_mutex_destroy=. + +*Вопрос* Рассмотрите [[./mutex-example-1.c][пример работы с мьютексом]] (файл =mutex-example-1.c=). Что будет если [[./mutex-example.c][убрать использование мьютекса]] (файл =mutex-example.c=)? Объясните поведение. + +*Вопрос* Подробнее про мьютексы читайте на стр. 374--377 учебника. + +** Семафоры + +Семафор --- это целочисленная переменная (типа =sem_t=), с которой можно совершать ряд действий: + - Инициализировать её некоторым значением, функция =sem_init=. Семафор может использоваться в том числе для синхронизации процессов, для этого его следует инициализировать до вызова =fork=, используя общую память. + - Войти (wait, enter) --- если значение переменной не 0, то выполнить декремент (уменьшить на 1) и продолжить выполнение. В противном случае ожидать увеличения значения переменной, после чего выполнить декремент и продолжить выполнение. Релизуется функцией =sem_wait=. + - Выйти (post, leave) --- выполнить инкремент. Релизуется функцией =sem_post=. + +Семафоры позволяют организовать синхронизацию между параллельнымы потоками различными способами, напрмер: + - Запретить более чем заданному количеству потоков выполнять фрагмент кода параллельно. + - Заставить один поток ожидать выполнения действия другого потока. + +*Вопрос* Подробнее про семафоры читайте на стр. 382--384 учебника. + +*Вопрос* Чем семафоры отличаются от мьютексов? Чем семафор с двумя состояниями отличается от мьютекса? + +*Задание 3* Используте семафор для синхронизации между потоками в *Задании 2*. + +При выполнении задания 3 для синхронизации паралельных потоков и корректного завершения работы программы вам может понадобиться использовать несколько семафоров. Также может пригодиться функция =sem_trywait=, которая не блокирует вычисления в случае, если войти не удалось, а возврящает код ошибки (подробнее см. =man sem_trywait=). + +* Что такое модель памяти + +Для начала подумаем про компилятор языка. +Описание алгоритма в программе включает в себя операции чтения и записи в память. +Программист использует эти операции в том порядке, в котором ему удобно, но этот порядок может быть не самым производительным. +Например, такие операции: + +#+begin_src c +int x = 10; +int y = 993; +int z = y + x; +print(y); +#+end_src + +можно перемешать многими способами, например: + +#+begin_src c +int y = 993; +int x = 10; +print(y); +int z = y + x; +#+end_src + +или: + +#+begin_src c +int y = 993; +print(y); +int x = 10; +int z = y + x; +#+end_src + +Чтобы повысить производительность кода компилятор переставляет операции, оптимизируя программу. +Такие перестановки называются /реордеринги/. +При реордерингах результат выполнения программы (например, ввод-вывод) должен остаться неизменным, иначе такую перестановку было бы делать ошибочно. + + +/Модель памяти/ определяет, какие перестановки чтений и записей допустимы. +Можно классифицировать их с помощью спектра: + +1) Очень слабые --- любые перестановки разрешены, пока они не меняют поведение однопоточной программы. +2) Слабые с зависимостями по данным --- нет перестановок, которые вмешиваются в косвенную адресацию. + Если операции описываются как =a <- load x, z <- load a=, то между ними не будут вставляться другие инструкции. + В первой категории даже это свойство не гарантируется. +3) Скорее сильные --- порядок записей сохраняется, чтения могут менять своё место. +4) Sequentially consistent --- вообще никакие операции чтения-записи не переставляются. + +Слабые разрешают больше перестановок, сильные --- меньше, и стремятся к полюсу sequentially consistent. + +Зачем эта градация? Реордеринги не видны когда код выполняется в одном потоке, но если есть несколько потоков и они взаимодействуют, то реордеринги начинают играть роль. +Например, в такой ситуации: + +#+begin_src c +int x = 0; +int y = 0; +void thread1() { + x = 1; + print(y); +} +void thread2() { + y = 1; + print(x); +} + +#+end_src + +*Вопрос* в чём проблема в этом коде? Какие пары чисел могут быть выведены в зависимости от того, в каком порядке будут выполнены инструкции разных потоков? Какое влияние оказывают перестановки компилятором? + + +Модель памяти может строиться для любого языка программирования или вообще вычислительной системы, где есть память. +Мы взглянем на две модели памяти: для абстрактного вычислителя C и для Intel 64. + +Реордеринги в C можно увидеть через действия компилятора, который меняет порядок инструкций. +В C достаточно слабая модель памяти. +Это роднит её с, например, моделью памяти процессоров ARM7. + + +В аппаратуре реордеринги случаются, например, при трансляции ассемблерных инструкций в микрокод, при которой порядок чтений и записей может измениться. +В конце мы увидим пример того, как их увидеть. + + +*Вопрос* Пусть произошли некоторые опасные реордеринги при компиляции. Будет ли из-за этого результат работы программы различным при каждом запуске? + + + +** Барьеры памяти + +/Барьер памяти/ это место в программе, в котором заданы ограничения на реордеринги. +Например, барьер по чтению может означать, что все операции чтения, которые были по тексту программы до барьера, должны произойти до него. +Реордеринги не смогут перекинуть никакое чтение до барьера в текст ассемблерной программы после него. + +Барьеры бывают разные: + +- Чтение +- Запись +- Полный (и то, и другое) +- Acquire (как полный, но операции после барьера не могут просочиться сквозь него) +- Release (как полный, но операции до барьера не могут просочиться сквозь него) + +GCC использует конструкцию =asm volatile(""::: "memory")= для общего барьера (реордеринги при компиляции). + +*Вопрос* если мы используем ассемблерные вставки в программы, как это связано с необходимостью добавлять в неё барьеры памяти на уровне компиляции? + +Intel64 использует инструкции: + +- =lfence= для барьера по чтению +- =sfence= для барьера по записи +- =mfence= для полного барьера + +Соответственно, самый полный барьер будет выглядеть как инструкция =mfence= внутри ассемблерной вставки, для которой также указан атрибут =memory=, запрещающий компилятору реордеринги: + +#+begin_src c +asm volatile("mfence"::: "memory") +#+end_src + + +*Задание 4* разберите пример =cpu-reordering.c=; он дублирует пример с чтениями и записью в =x= и =y=, но прогоняет его множество раз. При этом семафоры используются чтобы программа запускала вычисления в каждом потоке и по завершению итерации ждала, пока второй поток завершит свою итерацию. +Объясните, как в этой программе используются семафоры и как происходит детектирование реордерингов. Затем попробуйте вставить полные барьеры времени компиляции туда, где это необходимо. Попробуйте также вариант с полным барьером для компиляции и с соответствующей инструкцией процессора для полного барьера. Объясните результаты. + + +На низком уровне мьютексы и другие примитивы синхронизации реализованы с помощью барьеров. Действия, которые в коде происходят до работы с мьютексом или семафором, не должны оказаться из-за реордерингов после них. +Не пользуйтесь =volatile= для синхронизации между потоками! Полное объяснение на стр.362--363 учебника. + diff --git a/sem8/cpu-reordering.c b/sem8/cpu-reordering.c new file mode 100644 index 0000000..170a029 --- /dev/null +++ b/sem8/cpu-reordering.c @@ -0,0 +1,72 @@ +/* cpu-reordering.c */ + +#include +#include +#include +#include +#include +#include +#include +/* + * В этом коде происходит та же логика, что и в примере ранее. + Семафоры используются чтобы при каждом запуске итерации + в thread0_impl/thread1_impl в момент sem_post потоки + подождали друг друга. + */ +sem_t sem_begin0, sem_begin1, sem_end; + +int x, y, read0, read1; + +void *thread0_impl( void *param ) +{ + for (;;) { + sem_wait( &sem_begin0 ); + + x = 1; + read0 = y; + + sem_post( &sem_end ); + } + return NULL; +} + +void *thread1_impl( void *param ) +{ + for (;;) { + sem_wait( &sem_begin1 ); + + y = 1; + read1 = x; + + sem_post( &sem_end ); + } + return NULL; +} + +int main( void ) { + sem_init( &sem_begin0, 0, 0); + sem_init( &sem_begin1, 0, 0); + sem_init( &sem_end, 0, 0); + + pthread_t thread0, thread1; + pthread_create( &thread0, NULL, thread0_impl, NULL); + pthread_create( &thread1, NULL, thread1_impl, NULL); + + for (uint64_t i = 0; i < 1000000; i++) + { + x = 0; + y = 0; + sem_post( &sem_begin0 ); + sem_post( &sem_begin1 ); + + sem_wait( &sem_end ); + sem_wait( &sem_end ); + + if (read0 == 0 && read1 == 0 ) { + printf( "reordering happened on iteration %" PRIu64 "\n", i ); + exit(0); + } + } + puts("No reordering detected during 1000000 iterations"); + return 0; +} diff --git a/sem8/fork-example-1.c b/sem8/fork-example-1.c new file mode 100644 index 0000000..a172a51 --- /dev/null +++ b/sem8/fork-example-1.c @@ -0,0 +1,30 @@ +/* fork-example-1.c */ + +#include +#include +#include +#include +#include + +void* create_shared_memory(size_t size) { + return mmap(NULL, + size, + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, + -1, 0); +} + + +int main() { + void* shmem = create_shared_memory(128); + + printf("Shared memory at: %p\n" , shmem); + int pid = fork(); + + if (pid == 0) { + while (1); + } else { + printf("Child's pid is: %d\n", pid); + while(1); + } +} diff --git a/sem8/fork-example.c b/sem8/fork-example.c new file mode 100644 index 0000000..419f7c7 --- /dev/null +++ b/sem8/fork-example.c @@ -0,0 +1,19 @@ +/* fork-example.c */ + +#include +#include + +int main() { + // pid_t это, как и int, численный тип для идентификаторов процессов + pid_t pid = fork(); + // в зависимости от возвращаемого значения, которое попадёт в pid, + // мы поймём, находимся ли мы в родительском процессе или в дочернем. + if (pid == 0) { + printf("I am a child, pid was %d\n", pid); + printf("Child's pid is %d\n", getpid()); + } + else { + printf("I am a parent, pid was %d\n", pid); + printf("Parent's pid is %d\n", getpid()); + } +} diff --git a/sem8/mutex-example-1.c b/sem8/mutex-example-1.c new file mode 100644 index 0000000..992ee5e --- /dev/null +++ b/sem8/mutex-example-1.c @@ -0,0 +1,34 @@ +/* mutex-example-1.c */ + +#include +#include +#include +#include + +pthread_mutex_t m; +pthread_t t1, t2; +uint64_t value = 0; + +void* my_thread(void *_) +{ + for (int n = 0; n < 1000000; n++) + { + pthread_mutex_lock(&m); + value += 1; + pthread_mutex_unlock(&m); + } + return NULL; +} + +int main(void) +{ + pthread_mutex_init(&m, NULL); + pthread_create(&t1, NULL, my_thread, NULL); + pthread_create(&t2, NULL, my_thread, NULL); + pthread_join(t1, NULL); + pthread_join(t2, NULL); + printf("%"PRIu64"\n", value); + pthread_mutex_destroy(&m); + + return 0; +} diff --git a/sem8/mutex-example.c b/sem8/mutex-example.c new file mode 100644 index 0000000..478dc81 --- /dev/null +++ b/sem8/mutex-example.c @@ -0,0 +1,27 @@ +/* mutex-example.c */ + +#include +#include +#include +#include + +uint64_t value = 0; + +void* my_thread(void *_) +{ + for (int n = 0; n < 1000000; n++) + value += 1; + return NULL; +} + +int main(void) +{ + pthread_t t1, t2; + pthread_create(&t1, NULL, my_thread, NULL); + pthread_create(&t2, NULL, my_thread, NULL); + pthread_join(t1, NULL); + pthread_join(t2, NULL); + printf("%"PRIu64"\n", value); + + return 0; +} diff --git a/sem8/pipe-example-1.c b/sem8/pipe-example-1.c new file mode 100644 index 0000000..2b29dcc --- /dev/null +++ b/sem8/pipe-example-1.c @@ -0,0 +1,180 @@ +/* pipe-example-1.c */ + +#include +#include +#include +#include +#include + +enum +{ + MSG_STRING = 1, + MSG_END +}; + +enum +{ + MESSAGE_MAGIC = 0xAFAF, // magic signature value + MAX_MESSAGE_LEN = 4096 // maximum message length +}; + +struct __attribute__((packed)) message_header +{ + uint16_t magic; // magic signature + uint16_t type; // type of the message + uint16_t data_len; // length of data +}; + +enum +{ + // maximum data length + MAX_MESSAGE_DATA_LEN = MAX_MESSAGE_LEN - sizeof(struct message_header) +}; + +struct __attribute__((packed)) message +{ + struct message_header header; + // payload + uint8_t data[MAX_MESSAGE_DATA_LEN]; +}; + +struct message simple_message(uint16_t type) +{ + return (struct message) {(struct message_header) {MESSAGE_MAGIC, type, 0}, 0}; +} + +struct message string_message(const char *str) +{ + struct message msg = (struct message) {(struct message_header) {MESSAGE_MAGIC, MSG_STRING, strlen(str + 1)}, 0}; + strcpy(msg.data, str); + return msg; +} + +int send(int fd, const struct message *msg) +{ + /* Check if the input data is not empty */ + if (fd < 0 || msg == NULL) + return -1; + + /* Calculate the message size to send */ + int msg_size = sizeof(struct message_header) + msg->header.data_len; + + /* Check if message payload size is valid */ + if (msg->header.data_len > MAX_MESSAGE_DATA_LEN) + return -1; + + /* Write data to the output pipe (we assume it is ready) */ + if (write(fd, msg, msg_size) != msg_size) + return -2; + + return 0; +} + +int receive(int fd, struct message *msg) +{ + /* Check if the input data is not empty */ + if (fd < 0 || msg == NULL) + return -1; + + /* Try to read header */ + int msg_size = read(fd, &msg->header, sizeof(struct message_header)); + if (msg_size == 0) + return 0; + + /* Check header magic */ + if (msg->header.magic != MESSAGE_MAGIC) + return -2; + + /* Check if message has payload */ + if (msg->header.data_len > MAX_MESSAGE_DATA_LEN) + return -2; + if (msg->header.data_len > 0) + msg_size += read(fd, &msg->data, msg->header.data_len); + + /* Return number of bytes read */ + return msg_size; +} + + +int main() { + // Создадим два конвейера + int pipes[2][2]; + pipe(pipes[0]); + pipe(pipes[1]); + + // Создадим дочерний процесс + pid_t pid = fork(); + if (pid == 0) { + // Сохраним нужные дескпиторы конвейеров + int to_parent_pipe = pipes[1][1]; + int from_parent_pipe = pipes[0][0]; + + // И закроем ненужные + close(pipes[1][0]); + close(pipes[0][1]); + + // Будем читать строки и отправлять их сообщениями + char str[MAX_MESSAGE_DATA_LEN]; + for (;;) + { + // Прочитаем строку + if (fgets(str, MAX_MESSAGE_DATA_LEN, stdin) == NULL) + return 0; + if (strlen(str) <= 1) + break; + + // И отпавим её родителю + struct message msg = string_message(str); + send(to_parent_pipe, &msg); + } + + // Отправим сообщение о завершении ввода + struct message msg = simple_message(MSG_END); + send(to_parent_pipe, &msg); + + // Закроем дескпиторы + close(to_parent_pipe); + close(from_parent_pipe); + + return 0; + } + + // Далее выполняется только родительский поток + // Сохраним нужные дескпиторы конвейеров + int from_child_pipe = pipes[1][0]; + int to_child_pipe = pipes[0][1]; + + // И закроем ненужные + close(pipes[1][1]); + close(pipes[0][0]); + + // Будем ждать, пока ребенок не пришлет сообщение + struct message msg; + while (1) + { + int ret; + while (ret = receive(from_child_pipe, &msg) == 0) + ; + if (ret < 0) + return 1; + + // Если это строка - выведем её + if (msg.header.type == MSG_STRING) + printf("Recieved string from child: %s\n", (char *)msg.data); + // Если конец ввода - прервемся + else if (msg.header.type == MSG_END) + { + printf("Recieved END from child\n"); + break; + } + } + + // Дождемся завершения ребенка + waitpid(pid, NULL, 0); + + // Закроем дескпиторы + close(from_child_pipe); + close(to_child_pipe); + + return 0; +} diff --git a/sem8/pipe-example.c b/sem8/pipe-example.c new file mode 100644 index 0000000..5811e63 --- /dev/null +++ b/sem8/pipe-example.c @@ -0,0 +1,54 @@ +/* pipe-example.c */ + +#include +#include +#include + +int main() { + int pipes[2][2]; + pipe(pipes[0]); + pipe(pipes[1]); + + pid_t pid = fork(); + if (pid == 0) { + // Сохраним нужные дескпиторы конвейеров + int to_parent_pipe = pipes[1][1]; + int from_parent_pipe = pipes[0][0]; + // И закроем ненужные + close(pipes[1][0]); + close(pipes[0][1]); + // Отпавим один байт родителю + char c = 'A'; + write(to_parent_pipe, &c, 1); + // И будем ждать, пока родитель не пришлет 1 байт в ответ + while (read(from_parent_pipe, &c, 1) == 0) + ; + printf("Recieved from parent: %c\n", c); + // Закроем дескпиторы + close(to_parent_pipe); + close(from_parent_pipe); + return 0; + } + else { + // Сохраним нужные дескпиторы конвейеров + int from_child_pipe = pipes[1][0]; + int to_child_pipe = pipes[0][1]; + // И закроем ненужные + close(pipes[1][1]); + close(pipes[0][0]); + // Будем ждать, пока ребенок не пришлет 1 байт + char c; + while (read(from_child_pipe, &c, 1) == 0) + ; + printf("Recieved from child: %c\n", c); + // И отправим ответ + c++; + write(to_child_pipe, &c, 1); + // Дождемся завершения ребенка + waitpid(pid, NULL, 0); + // Закроем дескпиторы + close(from_child_pipe); + close(to_child_pipe); + return 0; + } +}