main.qml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of NeuralNetwork project https://git.semlanik.org/semlanik/NeuralNetwork
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. import QtQuick 2.11
  26. import QtQuick.Window 2.11
  27. import QtQuick.Controls 1.4
  28. import snakesimulator 1.0
  29. ApplicationWindow {
  30. id: root
  31. visible: true
  32. property int tileSize: 20
  33. width: field.width*tileSize
  34. height: field.height*tileSize
  35. Rectangle {
  36. color: "#000000"
  37. anchors.fill: parent
  38. }
  39. Repeater {
  40. model: snake.pointsData.length
  41. Rectangle {
  42. color: "#ffffff"
  43. x: snake.pointsData[model.index].x*tileSize
  44. y: snake.pointsData[model.index].y*tileSize
  45. width: tileSize
  46. height: tileSize
  47. }
  48. }
  49. Rectangle {
  50. color: "#eeffee"
  51. x: field.food.x*tileSize
  52. y: field.food.y*tileSize
  53. width: tileSize
  54. height: tileSize
  55. }
  56. Column {
  57. anchors {
  58. right: parent.right
  59. top: parent.top
  60. margins: 10
  61. }
  62. Text {
  63. color: "#ddffee"
  64. text: "Generation: " + stats.generation
  65. }
  66. Text {
  67. color: "#ddffee"
  68. text: "Individual: " + stats.individual
  69. }
  70. Text {
  71. color: "#ddffee"
  72. text: "Move: " + stats.move
  73. }
  74. TextField {
  75. onAccepted: {
  76. client.setSpeed(parseInt(text, 10))
  77. }
  78. }
  79. }
  80. Connections {
  81. target: field
  82. onWidthChanged: {
  83. console.log("New width: " + field.width)
  84. }
  85. }
  86. }