Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
53165d18
Commit
53165d18
authored
Aug 27, 2016
by
Denis Khachko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
d8eaabd3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
528 additions
and
4 deletions
+528
-4
src/actors/robot/robotmodule.cpp
src/actors/robot/robotmodule.cpp
+524
-3
src/actors/robot/robotmodule.h
src/actors/robot/robotmodule.h
+4
-1
No files found.
src/actors/robot/robotmodule.cpp
View file @
53165d18
...
...
@@ -3454,9 +3454,25 @@ namespace ActorRobot {
rightWall
=
false
;
leftWall
=
false
;
}
void
CFieldItem
::
setWalls
(
int
wallByte
)
{
if
((
wallByte
&
UP_WALL
)
==
UP_WALL
)
upWall
=
true
;
else
upWall
=
false
;
if
((
wallByte
&
DOWN_WALL
)
==
DOWN_WALL
)
downWall
=
true
;
else
downWall
=
false
;
if
((
wallByte
&
LEFT_WALL
)
==
LEFT_WALL
)
leftWall
=
true
;
else
leftWall
=
false
;
if
((
wallByte
&
RIGHT_WALL
)
==
RIGHT_WALL
)
rightWall
=
true
;
else
rightWall
=
false
;
}
ConsoleField
::
ConsoleField
(
int
r
,
int
c
)
{
createField
(
r
,
c
);
roboRow
=
0
;
roboCol
=
0
;
};
void
ConsoleField
::
createField
(
int
r
,
int
c
)
{
rows
.
clear
();
for
(
int
row
=
0
;
row
<
r
;
row
++
)
{
QList
<
CFieldItem
*>
curRow
;
...
...
@@ -3471,10 +3487,7 @@ namespace ActorRobot {
}
rows
.
append
(
curRow
);
}
roboRow
=
0
;
roboCol
=
0
;
};
CFieldItem
*
ConsoleField
::
getItem
(
int
row
,
int
col
)
{
if
(
row
>
rows
.
count
()
-
1
||
col
>
rows
.
at
(
row
).
count
()
-
1
)
...
...
@@ -3517,6 +3530,513 @@ namespace ActorRobot {
return
true
;
}
int
ConsoleField
::
loadFromFile
(
QString
fileName
)
{
QFileInfo
fi
(
fileName
);
QString
name
=
fi
.
fileName
();
QString
tmp
=
""
;
QString
ctmp
;
QFile
l_File
(
fileName
);
int
NStrok
;
NStrok
=
0
;
QString
l_String
;
// long l_Err;
int
CurX
,
CurY
;
int
SizeX
,
SizeY
;
// Тестовый прогон
if
(
!
l_File
.
open
(
QIODevice
::
ReadOnly
))
{
return
1
;
}
// 1 stroka - razmery polya
tmp
=
l_File
.
readLine
();
//QMessageBox::information( 0, "", tmp, 0,0,0);
if
(
tmp
.
isNull
()
||
tmp
.
isEmpty
())
{
l_File
.
close
();
return
2
;
}
//QMessageBox::information( 0, "", tmp, 0,0,0);
while
(
tmp
.
left
(
1
)
==
";"
||
tmp
==
""
)
{
tmp
=
l_File
.
readLine
();
NStrok
++
;
if
(
tmp
.
isNull
())
{
return
1
;
}
}
tmp
=
tmp
.
simplified
();
QStringList
l_List
=
tmp
.
split
(
' '
);
if
(
l_List
.
count
()
!=
2
)
{
l_File
.
close
();
return
3
;
}
SizeX
=
(
l_List
[
0
]).
toInt
();
SizeY
=
(
l_List
[
1
]).
toInt
();
if
(
(
SizeX
<=
0
)
||
(
SizeY
<=
0
)
)
{
return
4
;
}
// field.destroyField();
// field.createField(l_List[0].toInt(),l_List[1].toInt());
// Вторая строка - положение робота
tmp
=
l_File
.
readLine
();
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
5
;
}
while
(
tmp
.
left
(
1
)
==
";"
||
tmp
==
""
)
{
tmp
=
l_File
.
readLine
();
NStrok
++
;
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
5
;
}
}
tmp
=
tmp
.
simplified
();
l_List
=
tmp
.
split
(
' '
);
// koordinaty robota
// proverka
if
((
l_List
[
0
]).
toInt
()
<
0
||
(
l_List
[
1
]).
toInt
()
<
0
)
{
l_File
.
close
();
return
6
;
}
if
((
l_List
[
0
]).
toInt
()
>
SizeX
||
(
l_List
[
1
]).
toInt
()
>
SizeY
)
{
l_File
.
close
();
return
6
;
}
// m_DefaultSett = l_Sett;
while
(
!
l_File
.
atEnd
())
{
//l_Err = l_File.readLine(l_String, 255);
tmp
=
QString
::
fromUtf8
(
l_File
.
readLine
());
NStrok
++
;
if
(
tmp
.
isNull
())
{
return
5
;
}
if
(
tmp
.
left
(
1
)
==
";"
||
tmp
==
""
)
{
continue
;
}
tmp
=
tmp
.
simplified
();
l_List
=
tmp
.
split
(
' '
);
if
(
l_List
.
count
()
==
0
)
continue
;
if
(
l_List
.
count
()
>
9
)
{
l_File
.
close
();
return
-
NStrok
;
}
if
(
l_List
.
count
()
<
6
)
{
l_File
.
close
();
qDebug
(
"N Lexem<6"
);
return
-
NStrok
;
};
bool
ok
;
CurX
=
l_List
[
0
].
toInt
(
&
ok
);
if
(
!
ok
)
{
l_File
.
close
();
qDebug
(
"Bad cur X<6"
);
return
-
NStrok
;
};
CurY
=
l_List
[
1
].
toInt
(
&
ok
);
if
(
!
ok
){
l_File
.
close
();
qDebug
(
"Bad curY <6"
);
return
-
NStrok
;
};
if
(
CurX
<
0
||
CurX
>
SizeX
||
CurY
<
0
||
CurY
>
SizeY
)
{
l_File
.
close
();
return
-
NStrok
;
}
if
(
l_List
[
4
].
toFloat
()
<
0
)
{
l_File
.
close
();
return
-
NStrok
;
}
if
(
l_List
[
5
].
toFloat
()
<
MIN_TEMP
)
{
l_File
.
close
();
return
-
NStrok
;
}
if
(
l_List
.
count
()
>=
7
)
{
QString
tmp1
=
l_List
[
6
];
//dlina lexemy dolzna ravnyatsa 1
if
(
!
(
tmp1
.
length
()
==
1
))
{
l_File
.
close
();
return
-
NStrok
;
}
}
if
(
l_List
.
count
()
>=
8
)
{
QString
tmp1
=
l_List
[
7
];
//dlina lexemy dolzna ravnyatsa 1
if
(
!
(
tmp1
.
length
()
==
1
))
{
l_File
.
close
();
return
-
NStrok
;
}
}
}
l_File
.
close
();
rows
.
clear
();
//реальный прогон
//destroyField();
if
(
!
l_File
.
open
(
QIODevice
::
ReadOnly
))
{
return
10
;
}
// 1 stroka - razmery polya
tmp
=
l_File
.
readLine
();
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
10
;
}
while
(
tmp
.
left
(
1
)
==
";"
||
tmp
==
""
)
{
tmp
=
QString
::
fromUtf8
(
l_File
.
readLine
());
NStrok
++
;
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
10
;
}
}
tmp
=
tmp
.
simplified
();
l_List
=
tmp
.
split
(
' '
);
if
(
l_List
.
count
()
!=
2
)
{
l_File
.
close
();
return
-
NStrok
;
}
SizeX
=
(
l_List
[
0
]).
toInt
();
SizeY
=
(
l_List
[
1
]).
toInt
();
// //NEW ROBO CODE
createField
(
SizeY
,
SizeX
);
//END
if
((
l_List
[
0
]).
toInt
()
<=
0
||
(
l_List
[
1
]).
toInt
()
<=
0
)
{
l_File
.
close
();
return
-
NStrok
;
}
// Вторая строка - положение робота
tmp
=
l_File
.
readLine
();
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
10
;
}
while
(
tmp
.
left
(
1
)
==
";"
||
tmp
==
""
)
{
tmp
=
l_File
.
readLine
();
NStrok
++
;
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
10
;
}
}
tmp
=
tmp
.
simplified
();
l_List
=
tmp
.
split
(
' '
);
// koordinaty robota
if
((
l_List
[
0
]).
toInt
()
<
0
||
(
l_List
[
1
]).
toInt
()
<
0
)
{
l_File
.
close
();
return
-
NStrok
;
}
if
((
l_List
[
0
]).
toInt
()
>
SizeX
||
(
l_List
[
1
]).
toInt
()
>
SizeY
)
{
l_File
.
close
();
return
-
NStrok
;
}
roboCol
=
(
l_List
[
0
]).
toInt
();
roboRow
=
(
l_List
[
1
]).
toInt
();
//InitialX = m_x;
//InitialY = m_y;
// delete []m_FieldDubl;
while
(
!
l_File
.
atEnd
())
{
tmp
=
QString
::
fromUtf8
(
l_File
.
readLine
());
NStrok
++
;
if
(
tmp
.
isNull
())
{
l_File
.
close
();
return
10
;
}
if
(
tmp
.
left
(
1
)
==
";"
||
tmp
==
""
)
{
continue
;
}
tmp
=
tmp
.
simplified
();
l_List
=
tmp
.
split
(
' '
);
if
(
l_List
.
count
()
==
0
)
continue
;
if
(
l_List
.
count
()
>
9
)
{
l_File
.
close
();
return
-
NStrok
;
}
CurX
=
l_List
[
0
].
toInt
();
CurY
=
l_List
[
1
].
toInt
();
if
(
CurX
<
0
||
CurX
>
SizeX
||
CurY
<
0
||
CurY
>
SizeY
)
{
l_File
.
close
();
return
-
NStrok
;
}
// TODO STENI
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
setWalls
((
l_List
[
2
]).
toInt
());
// int ix = (l_List[0]).toInt();
// int iy = (l_List[1]).toInt();
if
(
!
((
l_List
[
3
]).
toInt
()
==
0
))
{
getItem
(
CurY
,
CurX
)
->
IsColored
=
true
;
// //QMessageBox::information( 0, "","test1" , 0,0,0);
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
IsColored
=
false
;
}
qreal
radiation
=
(
l_List
[
4
].
replace
(
","
,
"."
)).
toDouble
();
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
radiation
=
radiation
;
if
(
l_List
[
4
].
toFloat
()
<
0
)
{
l_File
.
close
();
return
-
NStrok
;
}
qreal
temperature
=
(
l_List
[
5
].
replace
(
","
,
"."
)).
toDouble
();
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
temperature
=
temperature
;
if
(
l_List
[
5
].
toFloat
()
<
MIN_TEMP
)
{
l_File
.
close
();
return
-
NStrok
;
}
if
(
l_List
.
count
()
>=
7
)
{
QString
tmp1
=
l_List
[
6
];
//dlina lexemy dolzna ravnyatsa 1
if
(
!
(
tmp1
.
length
()
==
1
))
{
l_File
.
close
();
return
-
NStrok
;
}
//qDebug()<<QString::fromUtf8("Тест Up:")<<tmp1[0];
if
(
tmp1
[
0
]
!=
'$'
)
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
upChar
=
tmp1
[
0
];
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
upChar
=
' '
;
}
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
upChar
=
' '
;
}
if
(
l_List
.
count
()
>=
8
)
{
QString
tmp1
=
l_List
[
7
];
//dlina lexemy dolzna ravnyatsa 1
if
(
!
(
tmp1
.
length
()
==
1
))
{
l_File
.
close
();
return
-
NStrok
;
}
//qDebug()<<QString::fromUtf8("Тест Down:")<<tmp1[0];
if
(
tmp1
[
0
]
!=
'$'
)
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
downChar
=
tmp1
[
0
];
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
downChar
=
' '
;
}
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
downChar
=
' '
;
}
if
(
l_List
.
count
()
>=
9
)
{
QString
tmp1
=
l_List
[
8
];
//dlina lexemy dolzna ravnyatsa 1
if
(
!
(
tmp1
.
length
()
==
1
))
{
l_File
.
close
();
return
-
NStrok
;
}
if
(
tmp1
[
0
]
==
'1'
)
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
mark
=
true
;
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
mark
=
false
;
}
}
else
{
if
(
getItem
(
CurY
,
CurX
))
getItem
(
CurY
,
CurX
)
->
mark
=
false
;
}
}
l_File
.
close
();
qDebug
()
<<
"File "
<<
fileName
;
//robot->setZValue(100);
return
(
0
);
};
//+++++++Simple Robot
SimpleRobot
::
SimpleRobot
(
QGraphicsItem
*
parent
)
{
...
...
@@ -3861,6 +4381,7 @@ QString RobotModule::initialize(const QStringList &configurationParameters, cons
qDebug
()
<<
"Robot:Console mode"
;
curConsoleField
=
new
ConsoleField
(
10
,
15
);
DISPLAY
=
false
;
if
(
runtimeParameters
.
value
(
'f'
).
isValid
())
curConsoleField
->
loadFromFile
(
runtimeParameters
.
value
(
'f'
).
toString
());
return
""
;
}
qDebug
()
<<
"Robot:GuiMode"
;
...
...
src/actors/robot/robotmodule.h
View file @
53165d18
...
...
@@ -70,6 +70,7 @@ namespace ActorRobot {
class
EditLine
;
class
RobotModule
;
class
CFieldItem
{
public:
...
...
@@ -94,6 +95,7 @@ namespace ActorRobot {
{
public:
ConsoleField
(
int
w
,
int
h
);
void
createField
(
int
w
,
int
h
);
CFieldItem
*
getItem
(
int
row
,
int
col
);
CFieldItem
*
getCurItem
();
//Item with robot
bool
goLeft
();
...
...
@@ -104,9 +106,10 @@ namespace ActorRobot {
int
Rows
(){
return
roboRow
;}
int
robotRow
(){
return
roboRow
;}
int
robotCol
(){
return
roboCol
;}
int
loadFromFile
(
QString
filename
);
private:
QList
<
QList
<
CFieldItem
*>
>
rows
;
QList
<
QList
<
CFieldItem
*>
>
rows
;
int
roboRow
;
int
roboCol
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment